From 313b5bc8a81b2d60f3cab33f1db0dffc5bc96a00 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 6 Jul 2018 10:50:22 -0700 Subject: [PATCH] Acceptance test for jobs from different namespaces on a single client --- ui/mirage/factories/allocation.js | 2 ++ ui/tests/acceptance/client-detail-test.js | 42 +++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/ui/mirage/factories/allocation.js b/ui/mirage/factories/allocation.js index 6c1c20393..3336a9c15 100644 --- a/ui/mirage/factories/allocation.js +++ b/ui/mirage/factories/allocation.js @@ -125,6 +125,7 @@ export default Factory.extend({ ); const job = allocation.jobId ? server.db.jobs.find(allocation.jobId) : pickOne(server.db.jobs); + const namespace = allocation.namespace || job.namespace; const node = allocation.nodeId ? server.db.nodes.find(allocation.nodeId) : pickOne(server.db.nodes); @@ -147,6 +148,7 @@ export default Factory.extend({ ); allocation.update({ + namespace, jobId: job.id, nodeId: node.id, taskStateIds: states.mapBy('id'), diff --git a/ui/tests/acceptance/client-detail-test.js b/ui/tests/acceptance/client-detail-test.js index f1860c610..72204b92b 100644 --- a/ui/tests/acceptance/client-detail-test.js +++ b/ui/tests/acceptance/client-detail-test.js @@ -654,3 +654,45 @@ test('when the node has a drain stategy with a negative deadline, the drain stra ); }); }); + +moduleForAcceptance('Acceptance | client detail (multi-namespace)', { + beforeEach() { + server.create('node', 'forceIPv4', { schedulingEligibility: 'eligible' }); + node = server.db.nodes[0]; + + // Related models + server.create('namespace'); + server.create('namespace', { id: 'other-namespace' }); + + server.create('agent'); + + // Make a job for each namespace, but have both scheduled on the same node + server.create('job', { id: 'job-1', namespaceId: 'default', createAllocations: false }); + server.createList('allocation', 3, { nodeId: node.id }); + + server.create('job', { id: 'job-2', namespaceId: 'other-namespace', createAllocations: false }); + server.createList('allocation', 3, { nodeId: node.id, jobId: 'job-2' }); + }, +}); + +test('when the node has allocations on different namespaces, the associated jobs are fetched correctly', function(assert) { + window.localStorage.nomadActiveNamespace = 'other-namespace'; + + visit(`/clients/${node.id}`); + + andThen(() => { + assert.equal( + findAll('[data-test-allocation]').length, + server.db.allocations.length, + 'All allocations are scheduled on this node' + ); + assert.ok( + server.pretender.handledRequests.findBy('url', '/v1/job/job-1'), + 'Job One fetched correctly' + ); + assert.ok( + server.pretender.handledRequests.findBy('url', '/v1/job/job-2?namespace=other-namespace'), + 'Job Two fetched correctly' + ); + }); +});