github.com/aminovpavel/nomad@v0.11.8/ui/tests/integration/allocation-row-test.js (about) 1 import { module, test } from 'qunit'; 2 import { setupRenderingTest } from 'ember-qunit'; 3 import hbs from 'htmlbars-inline-precompile'; 4 import generateResources from '../../mirage/data/generate-resources'; 5 import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; 6 import { find, render } from '@ember/test-helpers'; 7 import Response from 'ember-cli-mirage/response'; 8 import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer'; 9 10 module('Integration | Component | allocation row', function(hooks) { 11 setupRenderingTest(hooks); 12 13 hooks.beforeEach(function() { 14 fragmentSerializerInitializer(this.owner); 15 this.store = this.owner.lookup('service:store'); 16 this.server = startMirage(); 17 this.server.create('namespace'); 18 this.server.create('node'); 19 this.server.create('job', { createAllocations: false }); 20 }); 21 22 hooks.afterEach(function() { 23 this.server.shutdown(); 24 }); 25 26 test('Allocation row polls for stats, even when it errors or has an invalid response', async function(assert) { 27 const component = this; 28 29 let currentFrame = 0; 30 let frames = [ 31 JSON.stringify({ ResourceUsage: generateResources() }), 32 JSON.stringify({ ResourceUsage: generateResources() }), 33 null, 34 '<Not>Valid JSON</Not>', 35 JSON.stringify({ ResourceUsage: generateResources() }), 36 ]; 37 38 this.server.get('/client/allocation/:id/stats', function() { 39 const response = frames[++currentFrame]; 40 41 // Disable polling to stop the EC task in the component 42 if (currentFrame >= frames.length) { 43 component.set('enablePolling', false); 44 } 45 46 if (response) { 47 return response; 48 } 49 return new Response(500, {}, ''); 50 }); 51 52 this.server.create('allocation', { clientStatus: 'running' }); 53 await this.store.findAll('allocation'); 54 55 const allocation = this.store.peekAll('allocation').get('firstObject'); 56 57 this.setProperties({ 58 allocation, 59 context: 'job', 60 enablePolling: true, 61 }); 62 63 await render(hbs` 64 {{allocation-row 65 allocation=allocation 66 context=context 67 enablePolling=enablePolling}} 68 `); 69 70 assert.equal( 71 this.server.pretender.handledRequests.filterBy( 72 'url', 73 `/v1/client/allocation/${allocation.get('id')}/stats` 74 ).length, 75 frames.length, 76 'Requests continue to be made after malformed responses and server errors' 77 ); 78 }); 79 80 test('Allocation row shows warning when it requires drivers that are unhealthy on the node it is running on', async function(assert) { 81 const node = this.server.schema.nodes.first(); 82 const drivers = node.drivers; 83 Object.values(drivers).forEach(driver => { 84 driver.Healthy = false; 85 driver.Detected = true; 86 }); 87 node.update({ drivers }); 88 89 this.server.create('allocation', { clientStatus: 'running' }); 90 await this.store.findAll('job'); 91 await this.store.findAll('node'); 92 await this.store.findAll('allocation'); 93 94 const allocation = this.store.peekAll('allocation').get('firstObject'); 95 96 this.setProperties({ 97 allocation, 98 context: 'job', 99 }); 100 101 await render(hbs` 102 {{allocation-row 103 allocation=allocation 104 context=context}} 105 `); 106 107 assert.ok(find('[data-test-icon="unhealthy-driver"]'), 'Unhealthy driver icon is shown'); 108 }); 109 110 test('Allocation row shows an icon indicator when it was preempted', async function(assert) { 111 const allocId = this.server.create('allocation', 'preempted').id; 112 const allocation = await this.store.findRecord('allocation', allocId); 113 114 this.setProperties({ allocation, context: 'job' }); 115 await render(hbs` 116 {{allocation-row 117 allocation=allocation 118 context=context}} 119 `); 120 121 assert.ok(find('[data-test-icon="preemption"]'), 'Preempted icon is shown'); 122 }); 123 124 test('when an allocation is not running, the utilization graphs are omitted', async function(assert) { 125 this.setProperties({ 126 context: 'job', 127 enablePolling: false, 128 }); 129 130 // All non-running statuses need to be tested 131 ['pending', 'complete', 'failed', 'lost'].forEach(clientStatus => 132 this.server.create('allocation', { clientStatus }) 133 ); 134 135 await this.store.findAll('allocation'); 136 137 const allocations = this.store.peekAll('allocation'); 138 139 for (const allocation of allocations.toArray()) { 140 this.set('allocation', allocation); 141 await this.render(hbs` 142 {{allocation-row 143 allocation=allocation 144 context=context 145 enablePolling=enablePolling}} 146 `); 147 148 const status = allocation.get('clientStatus'); 149 assert.notOk(find('[data-test-cpu] .inline-chart'), `No CPU chart for ${status}`); 150 assert.notOk(find('[data-test-mem] .inline-chart'), `No Mem chart for ${status}`); 151 } 152 }); 153 });