github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/ui/tests/integration/allocation-row-test.js (about) 1 import { getOwner } from '@ember/application'; 2 import { test, moduleForComponent } from 'ember-qunit'; 3 import wait from 'ember-test-helpers/wait'; 4 import hbs from 'htmlbars-inline-precompile'; 5 import generateResources from '../../mirage/data/generate-resources'; 6 import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; 7 import { find } from 'ember-native-dom-helpers'; 8 import Response from 'ember-cli-mirage/response'; 9 import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer'; 10 11 moduleForComponent('allocation-row', 'Integration | Component | allocation row', { 12 integration: true, 13 beforeEach() { 14 fragmentSerializerInitializer(getOwner(this)); 15 this.store = getOwner(this).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 afterEach() { 22 this.server.shutdown(); 23 }, 24 }); 25 26 test('Allocation row polls for stats, even when it errors or has an invalid response', 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 const backoffSequence = [50]; 38 39 this.server.get('/client/allocation/:id/stats', function() { 40 const response = frames[++currentFrame]; 41 42 // Disable polling to stop the EC task in the component 43 if (currentFrame >= frames.length) { 44 component.set('enablePolling', false); 45 } 46 47 if (response) { 48 return response; 49 } 50 return new Response(500, {}, ''); 51 }); 52 53 this.server.create('allocation'); 54 this.store.findAll('allocation'); 55 56 let allocation; 57 58 return wait() 59 .then(() => { 60 allocation = this.store.peekAll('allocation').get('firstObject'); 61 62 this.setProperties({ 63 allocation, 64 backoffSequence, 65 context: 'job', 66 enablePolling: true, 67 }); 68 69 this.render(hbs` 70 {{allocation-row 71 allocation=allocation 72 context=context 73 backoffSequence=backoffSequence 74 enablePolling=enablePolling}} 75 `); 76 return wait(); 77 }) 78 .then(() => { 79 assert.equal( 80 this.server.pretender.handledRequests.filterBy( 81 'url', 82 `/v1/client/allocation/${allocation.get('id')}/stats` 83 ).length, 84 frames.length, 85 'Requests continue to be made after malformed responses and server errors' 86 ); 87 }); 88 }); 89 90 test('Allocation row shows warning when it requires drivers that are unhealthy on the node it is running on', function(assert) { 91 const node = this.server.schema.nodes.first(); 92 const drivers = node.drivers; 93 Object.values(drivers).forEach(driver => { 94 driver.Healthy = false; 95 driver.Detected = true; 96 }); 97 node.update({ drivers }); 98 99 this.server.create('allocation'); 100 this.store.findAll('job'); 101 this.store.findAll('node'); 102 this.store.findAll('allocation'); 103 104 let allocation; 105 106 return wait() 107 .then(() => { 108 allocation = this.store.peekAll('allocation').get('firstObject'); 109 110 this.setProperties({ 111 allocation, 112 context: 'job', 113 }); 114 115 this.render(hbs` 116 {{allocation-row 117 allocation=allocation 118 context=context}} 119 `); 120 return wait(); 121 }) 122 .then(() => { 123 assert.ok(find('[data-test-icon="unhealthy-driver"]'), 'Unhealthy driver icon is shown'); 124 }); 125 });