Skip to content

Commit

Permalink
Test coverage for preemption on the allocation detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed Apr 22, 2019
1 parent c7e1598 commit 5aa938e
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 9 deletions.
6 changes: 4 additions & 2 deletions ui/app/routes/allocations/allocation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import Route from '@ember/routing/route';
export default Route.extend({
setupController(controller, model) {
// Suppress the preemptedByAllocation fetch error in the event it's a 404
const setPreempter = () => controller.set('preempter', model.preemptedByAllocation);
model.preemptedByAllocation.then(setPreempter, setPreempter);
if (model) {
const setPreempter = () => controller.set('preempter', model.preemptedByAllocation);
model.preemptedByAllocation.then(setPreempter, setPreempter);
}

return this._super(...arguments);
},
Expand Down
14 changes: 7 additions & 7 deletions ui/app/templates/allocations/allocation/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,23 @@
</span>
</span>
<span class="pair">
<span class="term">{{preempter.name}}</span>
{{#link-to "allocations.allocation" preempter data-test-allocation-link}}{{preempter.shortId}}{{/link-to}}
<span class="term" data-test-allocation-name>{{preempter.name}}</span>
{{#link-to "allocations.allocation" preempter data-test-allocation-id}}{{preempter.shortId}}{{/link-to}}
</span>
<span class="pair job-link"><span class="term">Job</span>
{{#link-to "jobs.job" preempter.job (query-params jobNamespace=preempter.job.namespace.id) data-test-job-link}}{{preempter.job.name}}{{/link-to}}
</span>
<span class="pair job-priority"><span class="term">Priority</span>
{{preempter.job.priority}}
<span data-test-job-priority>{{preempter.job.priority}}</span>
</span>
<span class="pair node-link"><span class="term">Client</span>
{{#link-to "clients.client" preempter.node data-test-client-link}}{{preempter.node.shortId}}{{/link-to}}
</span>
<span class="pair"><span class="term">Reserved CPU</span>
{{preempter.resources.cpu}} MHz
<span data-test-allocation-cpu>{{preempter.resources.cpu}} MHz</span>
</span>
<span class="pair"><span class="term">Reserved Memory</span>
{{preempter.resources.memory}} MiB
<span data-test-allocation-memory>{{preempter.resources.memory}} MiB</span>
</span>
</div>
</div>
Expand All @@ -131,7 +131,7 @@
</div>
{{/if}}

{{#if model.preemptedAllocations.length}}
{{#if (and model.preemptedAllocations.isFulfilled model.preemptedAllocations.length)}}
<div class="boxed-section" data-test-preemptions>
<div class="boxed-section-head">Preempted Allocations</div>
<div class="boxed-section-body">
Expand All @@ -151,7 +151,7 @@
<th>Memory</th>
{{/t.head}}
{{#t.body as |row|}}
{{allocation-row allocation=row.model context="job"}}
{{allocation-row allocation=row.model context="job" data-test-allocation=row.model.id}}
{{/t.body}}
{{/list-table}}
</div>
Expand Down
103 changes: 103 additions & 0 deletions ui/tests/acceptance/allocation-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,106 @@ module('Acceptance | allocation detail (not running)', function(hooks) {
);
});
});

module('Acceptance | allocation detail (preemptions)', function(hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

hooks.beforeEach(async function() {
server.create('agent');
node = server.create('node');
job = server.create('job', { createAllocations: false });
});

test('shows a dedicated section to the allocation that preempted this allocation', async function(assert) {
allocation = server.create('allocation', 'preempted');
const preempter = server.schema.find('allocation', allocation.preemptedByAllocation);
const preempterJob = server.schema.find('job', preempter.jobId);
const preempterClient = server.schema.find('node', preempter.nodeId);

await Allocation.visit({ id: allocation.id });
assert.ok(Allocation.wasPreempted, 'Preempted allocation section is shown');
assert.equal(Allocation.preempter.status, preempter.clientStatus, 'Preempter status matches');
assert.equal(Allocation.preempter.name, preempter.name, 'Preempter name matches');
assert.equal(
Allocation.preempter.priority,
preempterJob.priority,
'Preempter priority matches'
);

await Allocation.preempter.visit();
assert.equal(
currentURL(),
`/allocations/${preempter.id}`,
'Clicking the preempter id navigates to the preempter allocation detail page'
);

await Allocation.visit({ id: allocation.id });
await Allocation.preempter.visitJob();
assert.equal(
currentURL(),
`/jobs/${preempterJob.id}`,
'Clicking the preempter job link navigates to the preempter job page'
);

await Allocation.visit({ id: allocation.id });
await Allocation.preempter.visitClient();
assert.equal(
currentURL(),
`/clients/${preempterClient.id}`,
'Clicking the preempter client link navigates to the preempter client page'
);
});

test('shows a dedicated section to the allocations this allocation preempted', async function(assert) {
allocation = server.create('allocation', 'preempter');
await Allocation.visit({ id: allocation.id });
assert.ok(Allocation.preempted, 'The allocations this allocation preempted are shown');
});

test('each preempted allocation in the table lists basic allocation information', async function(assert) {
allocation = server.create('allocation', 'preempter');
await Allocation.visit({ id: allocation.id });

const preemption = allocation.preemptedAllocations
.map(id => server.schema.find('allocation', id))
.sortBy('modifyIndex')
.reverse()[0];
const preemptionRow = Allocation.preemptions.objectAt(0);

assert.equal(
Allocation.preemptions.length,
allocation.preemptedAllocations.length,
'The preemptions table has a row for each preempted allocation'
);

assert.equal(preemptionRow.shortId, preemption.id.split('-')[0], 'Preemption short id');
assert.equal(
preemptionRow.createTime,
moment(preemption.createTime / 1000000).format('MMM DD HH:mm:ss ZZ'),
'Preemption create time'
);
assert.equal(
preemptionRow.modifyTime,
moment(preemption.modifyTime / 1000000).fromNow(),
'Preemption modify time'
);
assert.equal(preemptionRow.status, preemption.clientStatus, 'Client status');
assert.equal(preemptionRow.jobVersion, preemption.jobVersion, 'Job Version');
assert.equal(
preemptionRow.client,
server.db.nodes.find(preemption.nodeId).id.split('-')[0],
'Node ID'
);

await preemptionRow.visitClient();
assert.equal(currentURL(), `/clients/${preemption.nodeId}`, 'Node links to node page');
});

test('when an allocation both preempted allocations and was preempted itself, both preemptions sections are shown', async function(assert) {
allocation = server.create('allocation', 'preempter', 'preempted');
await Allocation.visit({ id: allocation.id });
assert.ok(Allocation.preempted, 'The allocations this allocation preempted are shown');
assert.ok(Allocation.wasPreempted, 'Preempted allocation section is shown');
});
});

0 comments on commit 5aa938e

Please sign in to comment.