Integration tests for the various reschedule events timeline permutations

This commit is contained in:
Michael Lange
2018-05-04 19:04:36 -07:00
parent 658c8426ca
commit 94df7bc46a
5 changed files with 213 additions and 14 deletions

View File

@@ -24,8 +24,7 @@ export default Component.extend({
stats: null,
statsError: false,
// enablePolling: computed(() => !Ember.testing),
enablePolling: false,
enablePolling: computed(() => !Ember.testing),
onClick() {},

View File

@@ -1,17 +1,20 @@
<li class="timeline-note">
{{#if label}}
<strong data-test-reschedule-label>{{label}}</strong>
{{/if}}
{{moment-format time "MMMM D, YYYY HH:mm:ss"}}
</li>
<li class="timeline-object">
<li class="timeline-object" data-test-allocation={{allocation.id}}>
<div class="boxed-section">
{{#unless linkToAllocation}}
<div class="boxed-section-head">
<div class="boxed-section-head" data-test-row-heading>
This Allocation
</div>
{{/unless}}
<div class="boxed-section-body inline-definitions">
<div class="columns">
<div class="column is-centered is-minimum">
<span class="tag {{allocation.statusClass}}">
<span data-test-allocation-status class="tag {{allocation.statusClass}}">
{{allocation.clientStatus}}
</span>
</div>
@@ -21,16 +24,16 @@
<span class="term">Allocation</span>
{{#if linkToAllocation}}
{{#link-to "allocations.allocation" allocation.id}}
<code>{{allocation.shortId}}</code>
<code data-test-allocation-link>{{allocation.shortId}}</code>
{{/link-to}}
{{else}}
<code>{{allocation.shortId}}</code>
<code data-test-allocation-link>{{allocation.shortId}}</code>
{{/if}}
</span>
<span class="pair">
<span class="term">Client</span>
<span>
{{#link-to "clients.client" allocation.node.id}}
{{#link-to "clients.client" data-test-node-link allocation.node.id}}
<code>{{allocation.node.id}}</code>
{{/link-to}}
</span>

View File

@@ -6,18 +6,17 @@
time=allocation.nextAllocation.modifyTime}}
{{/if}}
{{#if allocation.hasStoppedRescheduling}}
<li class="timeline-note">
<li class="timeline-note" data-test-stop-warning>
{{x-icon "warning" class="is-warning is-text"}} Nomad has stopped attempting to reschedule this allocation.
</li>
{{/if}}
{{#if (and allocation.followUpEvaluation.waitUntil (not allocation.nextAllocation))}}
<li class="timeline-note">
<li class="timeline-note" data-test-attempt-notice>
{{x-icon "clock" class="is-info is-text"}} Nomad will attempt to reschedule
{{moment-from-now allocation.followUpEvaluation.waitUntil interval=1000}}
</li>
{{/if}}
{{reschedule-event-row
label="This Allocation"
allocation=allocation
linkToAllocation=false
time=allocation.modifyTime}}

View File

@@ -66,7 +66,7 @@ export default Factory.extend({
// After rescheduleAttempts hits zero, a final allocation is made with no nextAllocation and
// a clientStatus of failed or running, depending on rescheduleSuccess
afterCreate(allocation, server) {
const attempts = allocation.rescheduleAttempts;
const attempts = allocation.rescheduleAttempts - 1;
const previousEvents =
(allocation.rescheduleTracker && allocation.rescheduleTracker.Events) || [];
@@ -91,9 +91,9 @@ export default Factory.extend({
};
let nextAllocation;
if (attempts) {
if (attempts > 0) {
nextAllocation = server.create('allocation', 'rescheduled', {
rescheduleAttempts: Math.max(attempts - 1, 0),
rescheduleAttempts: Math.max(attempts, 0),
rescheduleSuccess: allocation.rescheduleSuccess,
previousAllocation: allocation.id,
clientStatus: 'failed',

View File

@@ -0,0 +1,198 @@
import { getOwner } from '@ember/application';
import { test, moduleForComponent } from 'ember-qunit';
import { find, findAll } from 'ember-native-dom-helpers';
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
import wait from 'ember-test-helpers/wait';
import hbs from 'htmlbars-inline-precompile';
import moment from 'moment';
moduleForComponent(
'reschedule-event-timeline',
'Integration | Component | reschedule event timeline',
{
integration: true,
beforeEach() {
this.store = getOwner(this).lookup('service:store');
this.server = startMirage();
this.server.create('namespace');
this.server.create('node');
this.server.create('job', { createAllocations: false });
},
afterEach() {
this.server.shutdown();
},
}
);
const commonTemplate = hbs`
{{reschedule-event-timeline allocation=allocation}}
`;
test('when the allocation is running, the timeline shows past allocations', function(assert) {
const attempts = 2;
this.server.create('allocation', 'rescheduled', {
rescheduleAttempts: attempts,
rescheduleSuccess: true,
});
this.store.findAll('allocation');
let allocation;
return wait()
.then(() => {
allocation = this.store
.peekAll('allocation')
.find(alloc => !alloc.get('nextAllocation.content'));
this.set('allocation', allocation);
this.render(commonTemplate);
return wait();
})
.then(() => {
assert.equal(
findAll('[data-test-allocation]').length,
attempts + 1,
'Total allocations equals current allocation plus all past allocations'
);
assert.equal(
find('[data-test-allocation]'),
find(`[data-test-allocation="${allocation.id}"]`),
'First allocation is the current allocation'
);
assert.notOk(find('[data-test-stop-warning]'), 'No stop warning');
assert.notOk(find('[data-test-attempt-notice]'), 'No attempt notice');
assert.equal(
find(
`[data-test-allocation="${allocation.id}"] [data-test-allocation-link]`
).textContent.trim(),
allocation.get('shortId'),
'The "this" allocation is correct'
);
assert.equal(
find(
`[data-test-allocation="${allocation.id}"] [data-test-allocation-status]`
).textContent.trim(),
allocation.get('clientStatus'),
'Allocation shows the status'
);
});
});
test('when the allocation has failed and there is a follow up evaluation, a note with a time is shown', function(assert) {
const attempts = 2;
this.server.create('allocation', 'rescheduled', {
rescheduleAttempts: attempts,
rescheduleSuccess: false,
});
this.store.findAll('allocation');
let allocation;
return wait()
.then(() => {
allocation = this.store
.peekAll('allocation')
.find(alloc => !alloc.get('nextAllocation.content'));
this.set('allocation', allocation);
this.render(commonTemplate);
return wait();
})
.then(() => {
assert.ok(
find('[data-test-stop-warning]'),
'Stop warning is shown since the last allocation failed'
);
assert.notOk(find('[data-test-attempt-notice]'), 'Reschdule attempt notice is not shown');
});
});
test('when the allocation has failed and there is no follow up evaluation, a warning is shown', function(assert) {
const attempts = 2;
this.server.create('allocation', 'rescheduled', {
rescheduleAttempts: attempts,
rescheduleSuccess: false,
});
const lastAllocation = server.schema.allocations.findBy({ nextAllocation: undefined });
lastAllocation.update({
followupEvalId: server.create('evaluation', {
waitUntil: moment()
.add(2, 'hours')
.toDate(),
}).id,
});
this.store.findAll('allocation');
let allocation;
return wait()
.then(() => {
allocation = this.store
.peekAll('allocation')
.find(alloc => !alloc.get('nextAllocation.content'));
this.set('allocation', allocation);
this.render(commonTemplate);
return wait();
})
.then(() => {
assert.ok(
find('[data-test-attempt-notice]'),
'Reschedule notice is shown since the follow up eval says so'
);
assert.notOk(find('[data-test-stop-warning]'), 'Stop warning is not shown');
});
});
test('when the allocation has a next allocation already, it is shown in the timeline', function(assert) {
const attempts = 2;
const originalAllocation = this.server.create('allocation', 'rescheduled', {
rescheduleAttempts: attempts,
rescheduleSuccess: true,
});
this.store.findAll('allocation');
let allocation;
return wait()
.then(() => {
allocation = this.store.peekAll('allocation').findBy('id', originalAllocation.id);
this.set('allocation', allocation);
this.render(commonTemplate);
return wait();
})
.then(() => {
assert.ok(
find('[data-test-reschedule-label]').textContent.trim(),
'Next Allocation',
'The first allocation is the next allocation and labeled as such'
);
assert.equal(
find('[data-test-allocation] [data-test-allocation-link]').textContent.trim(),
allocation.get('nextAllocation.shortId'),
'The next allocation item is for the correct allocation'
);
assert.equal(
findAll('[data-test-allocation]')[1],
find(`[data-test-allocation="${allocation.id}"]`),
'Second allocation is the current allocation'
);
assert.notOk(find('[data-test-stop-warning]'), 'No stop warning');
assert.notOk(find('[data-test-attempt-notice]'), 'No attempt notice');
});
});