open-nomad/ui/tests/integration/components/allocation-row-test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

172 lines
5.1 KiB
JavaScript
Raw Normal View History

2019-03-13 00:04:16 +00:00
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
2018-04-21 01:11:32 +00:00
import hbs from 'htmlbars-inline-precompile';
import generateResources from '../../../mirage/data/generate-resources';
2018-04-21 01:11:32 +00:00
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
import { find, render } from '@ember/test-helpers';
2018-04-21 01:11:32 +00:00
import Response from 'ember-cli-mirage/response';
import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer';
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
2018-04-21 01:11:32 +00:00
2022-01-20 15:39:02 +00:00
module('Integration | Component | allocation row', function (hooks) {
2019-03-13 00:04:16 +00:00
setupRenderingTest(hooks);
2022-01-20 15:39:02 +00:00
hooks.beforeEach(function () {
2019-03-13 00:04:16 +00:00
fragmentSerializerInitializer(this.owner);
this.store = this.owner.lookup('service:store');
2018-04-21 01:11:32 +00:00
this.server = startMirage();
this.server.create('namespace');
this.server.create('node');
this.server.create('job', { createAllocations: false });
2019-03-13 00:04:16 +00:00
});
2018-04-21 01:11:32 +00:00
2022-01-20 15:39:02 +00:00
hooks.afterEach(function () {
2019-03-13 00:04:16 +00:00
this.server.shutdown();
2018-04-21 01:11:32 +00:00
});
2022-01-20 15:39:02 +00:00
test('Allocation row polls for stats, even when it errors or has an invalid response', async function (assert) {
2019-03-13 00:04:16 +00:00
const component = this;
let currentFrame = 0;
let frames = [
JSON.stringify({ ResourceUsage: generateResources() }),
JSON.stringify({ ResourceUsage: generateResources() }),
null,
'<Not>Valid JSON</Not>',
2022-01-20 15:39:02 +00:00
JSON.stringify({ ResourceUsage: generateResources() }),
2019-03-13 00:04:16 +00:00
];
2022-01-20 15:39:02 +00:00
this.server.get('/client/allocation/:id/stats', function () {
2019-03-13 00:04:16 +00:00
const response = frames[++currentFrame];
// Disable polling to stop the EC task in the component
if (currentFrame >= frames.length) {
component.set('enablePolling', false);
}
if (response) {
return response;
}
return new Response(500, {}, '');
});
this.server.create('allocation', { clientStatus: 'running' });
await this.store.findAll('allocation');
2019-03-13 00:04:16 +00:00
const allocation = this.store.peekAll('allocation').get('firstObject');
2018-04-21 01:11:32 +00:00
this.setProperties({
allocation,
context: 'job',
2022-01-20 15:39:02 +00:00
enablePolling: true,
});
2018-04-21 01:11:32 +00:00
await render(hbs`
<AllocationRow
@allocation={{allocation}}
@context={{context}}
@enablePolling={{enablePolling}} />
`);
2018-04-21 01:11:32 +00:00
assert.equal(
this.server.pretender.handledRequests.filterBy(
'url',
`/v1/client/allocation/${allocation.get('id')}/stats`
).length,
frames.length,
'Requests continue to be made after malformed responses and server errors'
);
2019-03-13 00:04:16 +00:00
});
2018-04-21 01:11:32 +00:00
2022-01-20 15:39:02 +00:00
test('Allocation row shows warning when it requires drivers that are unhealthy on the node it is running on', async function (assert) {
assert.expect(2);
2019-03-13 00:04:16 +00:00
const node = this.server.schema.nodes.first();
const drivers = node.drivers;
2022-01-20 15:39:02 +00:00
Object.values(drivers).forEach((driver) => {
2019-03-13 00:04:16 +00:00
driver.Healthy = false;
driver.Detected = true;
2018-04-21 01:11:32 +00:00
});
2019-03-13 00:04:16 +00:00
node.update({ drivers });
2019-03-13 00:04:16 +00:00
this.server.create('allocation', { clientStatus: 'running' });
await this.store.findAll('job');
await this.store.findAll('node');
await this.store.findAll('allocation');
const allocation = this.store.peekAll('allocation').get('firstObject');
this.setProperties({
allocation,
2022-01-20 15:39:02 +00:00
context: 'job',
});
await render(hbs`
<AllocationRow
@allocation={{allocation}}
@context={{context}} />
`);
2021-12-28 16:08:12 +00:00
assert.ok(
find('[data-test-icon="unhealthy-driver"]'),
'Unhealthy driver icon is shown'
);
await componentA11yAudit(this.element, assert);
2019-03-13 00:04:16 +00:00
});
2022-01-20 15:39:02 +00:00
test('Allocation row shows an icon indicator when it was preempted', async function (assert) {
assert.expect(2);
const allocId = this.server.create('allocation', 'preempted').id;
const allocation = await this.store.findRecord('allocation', allocId);
this.setProperties({ allocation, context: 'job' });
await render(hbs`
<AllocationRow
@allocation={{allocation}}
@context={{context}} />
`);
assert.ok(find('[data-test-icon="preemption"]'), 'Preempted icon is shown');
await componentA11yAudit(this.element, assert);
});
2022-01-20 15:39:02 +00:00
test('when an allocation is not running, the utilization graphs are omitted', async function (assert) {
assert.expect(8);
2019-03-13 00:04:16 +00:00
this.setProperties({
context: 'job',
2022-01-20 15:39:02 +00:00
enablePolling: false,
});
2018-12-11 01:28:23 +00:00
2019-03-13 00:04:16 +00:00
// All non-running statuses need to be tested
2022-01-20 15:39:02 +00:00
['pending', 'complete', 'failed', 'lost'].forEach((clientStatus) =>
2019-03-13 00:04:16 +00:00
this.server.create('allocation', { clientStatus })
2018-12-11 01:28:23 +00:00
);
await this.store.findAll('allocation');
2018-12-11 01:28:23 +00:00
const allocations = this.store.peekAll('allocation');
2018-12-11 01:28:23 +00:00
for (const allocation of allocations.toArray()) {
this.set('allocation', allocation);
await render(hbs`
<AllocationRow
@allocation={{allocation}}
@context={{context}}
@enablePolling={{enablePolling}} />
`);
2018-12-11 01:28:23 +00:00
const status = allocation.get('clientStatus');
2021-12-28 16:08:12 +00:00
assert.notOk(
find('[data-test-cpu] .inline-chart'),
`No CPU chart for ${status}`
);
assert.notOk(
find('[data-test-mem] .inline-chart'),
`No Mem chart for ${status}`
);
}
});
2019-03-13 00:04:16 +00:00
});