Reflect alloc-id-having mocks in tests

This commit is contained in:
Phil Renaud 2022-09-08 16:03:56 -04:00
parent 2bce572292
commit 84ed47299d
3 changed files with 32 additions and 10 deletions

View File

@ -38,14 +38,13 @@ export default class AllocationServiceSidebarComponent extends Component {
} }
get checks() { get checks() {
if (!this.args.service || !this.args.allocation) return null; if (!this.args.service || !this.args.allocation) return [];
let allocID = this.args.allocation.id; let allocID = this.args.allocation.id;
// Our UI checks run every 2 seconds; but a check itself may only update every, say, minute. // Our UI checks run every 2 seconds; but a check itself may only update every, say, minute.
// Therefore, we'll have duplicate checks in a service's healthChecks array. // Therefore, we'll have duplicate checks in a service's healthChecks array.
// Only get the most recent check for each check. // Only get the most recent check for each check.
return (this.args.service.healthChecks || []) return (this.args.service.healthChecks || [])
.filterBy('Alloc', allocID) .filterBy('Alloc', allocID)
.uniqBy('Timestamp')
.sortBy('Timestamp') .sortBy('Timestamp')
.reverse() .reverse()
.uniqBy('Check') .uniqBy('Check')

View File

@ -627,7 +627,7 @@ module('Acceptance | allocation detail (services)', function (hooks) {
server.createList('agent', 3, 'withConsulLink', 'withVaultLink'); server.createList('agent', 3, 'withConsulLink', 'withVaultLink');
server.createList('node', 5); server.createList('node', 5);
server.createList('job', 1, { createRecommendations: true }); server.createList('job', 1, { createRecommendations: true });
server.create('job', { const job = server.create('job', {
withGroupServices: true, withGroupServices: true,
withTaskServices: true, withTaskServices: true,
name: 'Service-haver', name: 'Service-haver',
@ -635,12 +635,16 @@ module('Acceptance | allocation detail (services)', function (hooks) {
namespaceId: 'default', namespaceId: 'default',
}); });
const currentAlloc = server.db.allocations.findBy({ jobId: job.id });
const otherAlloc = server.db.allocations.reject((j) => j.jobId !== job.id);
server.db.serviceFragments.update({ server.db.serviceFragments.update({
healthChecks: [ healthChecks: [
{ {
Status: 'success', Status: 'success',
Check: 'check1', Check: 'check1',
Timestamp: 99, Timestamp: 99,
Alloc: currentAlloc.id,
}, },
{ {
Status: 'failure', Status: 'failure',
@ -649,18 +653,30 @@ module('Acceptance | allocation detail (services)', function (hooks) {
propThatDoesntMatter: propThatDoesntMatter:
'this object will be ignored, since it shared a Check name with a later one.', 'this object will be ignored, since it shared a Check name with a later one.',
Timestamp: 98, Timestamp: 98,
Alloc: currentAlloc.id,
}, },
{ {
Status: 'success', Status: 'success',
Check: 'check2', Check: 'check2',
Output: 'Two', Output: 'Two',
Timestamp: 99, Timestamp: 99,
Alloc: currentAlloc.id,
}, },
{ {
Status: 'failure', Status: 'failure',
Check: 'check3', Check: 'check3',
Output: 'Oh no!', Output: 'Oh no!',
Timestamp: 99, Timestamp: 99,
Alloc: currentAlloc.id,
},
{
Status: 'success',
Check: 'check3',
Output: 'Wont be seen',
propThatDoesntMatter:
'this object will be ignored, in spite of its later timestamp, since it exists on a different alloc',
Timestamp: 100,
Alloc: otherAlloc.id,
}, },
], ],
}); });
@ -669,7 +685,6 @@ module('Acceptance | allocation detail (services)', function (hooks) {
test('Allocation has a list of services with active checks', async function (assert) { test('Allocation has a list of services with active checks', async function (assert) {
await visit('jobs/service-haver@default'); await visit('jobs/service-haver@default');
await click('.allocation-row'); await click('.allocation-row');
assert.dom('[data-test-service]').exists(); assert.dom('[data-test-service]').exists();
assert.dom('.service-sidebar').exists(); assert.dom('.service-sidebar').exists();
assert.dom('.service-sidebar').doesNotHaveClass('open'); assert.dom('.service-sidebar').doesNotHaveClass('open');

View File

@ -9,8 +9,7 @@ module('Unit | Controller | allocations/allocation/index', function (hooks) {
let controller = this.owner.lookup( let controller = this.owner.lookup(
'controller:allocations/allocation/index' 'controller:allocations/allocation/index'
); );
controller.set('model', JSON.parse(JSON.stringify(Allocation)));
controller.set('model', Allocation);
const groupFakePy = { const groupFakePy = {
refID: 'fakepy-group-fake-py', refID: 'fakepy-group-fake-py',
@ -95,12 +94,11 @@ module('Unit | Controller | allocations/allocation/index', function (hooks) {
); );
}); });
test('it handles duplicate names', function (assert) { test('it handles duplicate names', async function (assert) {
let controller = this.owner.lookup( let controller = this.owner.lookup(
'controller:allocations/allocation/index' 'controller:allocations/allocation/index'
); );
controller.set('model', JSON.parse(JSON.stringify(Allocation)));
controller.set('model', Allocation);
const groupDupe = { const groupDupe = {
refID: 'fakepy-duper', refID: 'fakepy-duper',
@ -229,6 +227,7 @@ var Allocation = {
healthChecks: { healthChecks: {
c97fda942e772b43a5a537e5b0c8544c: { c97fda942e772b43a5a537e5b0c8544c: {
Check: 'service: "task-fake-py" check', Check: 'service: "task-fake-py" check',
Alloc: 'my-alloc',
Group: 'trying-multi-dupes.fakepy[1]', Group: 'trying-multi-dupes.fakepy[1]',
ID: 'c97fda942e772b43a5a537e5b0c8544c', ID: 'c97fda942e772b43a5a537e5b0c8544c',
Mode: 'healthiness', Mode: 'healthiness',
@ -241,6 +240,7 @@ var Allocation = {
}, },
'2e1bfc8ecc485ee86b972ae08e890152': { '2e1bfc8ecc485ee86b972ae08e890152': {
Check: 'task-happy', Check: 'task-happy',
Alloc: 'my-alloc',
Group: 'trying-multi-dupes.fakepy[1]', Group: 'trying-multi-dupes.fakepy[1]',
ID: '2e1bfc8ecc485ee86b972ae08e890152', ID: '2e1bfc8ecc485ee86b972ae08e890152',
Mode: 'healthiness', Mode: 'healthiness',
@ -253,6 +253,7 @@ var Allocation = {
}, },
'6162723ab20b268c25eda69b400dc9c6': { '6162723ab20b268c25eda69b400dc9c6': {
Check: 'task-sad', Check: 'task-sad',
Alloc: 'my-alloc',
Group: 'trying-multi-dupes.fakepy[1]', Group: 'trying-multi-dupes.fakepy[1]',
ID: '6162723ab20b268c25eda69b400dc9c6', ID: '6162723ab20b268c25eda69b400dc9c6',
Mode: 'healthiness', Mode: 'healthiness',
@ -266,6 +267,7 @@ var Allocation = {
}, },
a4a7050175a2b236edcf613cb3563753: { a4a7050175a2b236edcf613cb3563753: {
Check: 'task-sad2', Check: 'task-sad2',
Alloc: 'my-alloc',
Group: 'trying-multi-dupes.fakepy[1]', Group: 'trying-multi-dupes.fakepy[1]',
ID: 'a4a7050175a2b236edcf613cb3563753', ID: 'a4a7050175a2b236edcf613cb3563753',
Mode: 'healthiness', Mode: 'healthiness',
@ -279,6 +281,7 @@ var Allocation = {
}, },
'2dfe58eb841bdfa704f0ae9ef5b5af5e': { '2dfe58eb841bdfa704f0ae9ef5b5af5e': {
Check: 'tcp_probe', Check: 'tcp_probe',
Alloc: 'my-alloc',
Group: 'trying-multi-dupes.fakepy[1]', Group: 'trying-multi-dupes.fakepy[1]',
ID: '2dfe58eb841bdfa704f0ae9ef5b5af5e', ID: '2dfe58eb841bdfa704f0ae9ef5b5af5e',
Mode: 'readiness', Mode: 'readiness',
@ -290,6 +293,7 @@ var Allocation = {
}, },
'69021054964f4c461b3c4c4f456e16a8': { '69021054964f4c461b3c4c4f456e16a8': {
Check: 'happy', Check: 'happy',
Alloc: 'my-alloc',
Group: 'trying-multi-dupes.fakepy[1]', Group: 'trying-multi-dupes.fakepy[1]',
ID: '69021054964f4c461b3c4c4f456e16a8', ID: '69021054964f4c461b3c4c4f456e16a8',
Mode: 'healthiness', Mode: 'healthiness',
@ -301,6 +305,7 @@ var Allocation = {
}, },
'913f5b725ceecdd5ff48a9a51ddf8513': { '913f5b725ceecdd5ff48a9a51ddf8513': {
Check: 'sad', Check: 'sad',
Alloc: 'my-alloc',
Group: 'trying-multi-dupes.fakepy[1]', Group: 'trying-multi-dupes.fakepy[1]',
ID: '913f5b725ceecdd5ff48a9a51ddf8513', ID: '913f5b725ceecdd5ff48a9a51ddf8513',
Mode: 'healthiness', Mode: 'healthiness',
@ -313,6 +318,7 @@ var Allocation = {
}, },
bloop: { bloop: {
Check: 'is-alive', Check: 'is-alive',
Alloc: 'my-alloc',
Group: 'trying-multi-dupes.fakepy[1]', Group: 'trying-multi-dupes.fakepy[1]',
ID: 'bloop', ID: 'bloop',
Mode: 'healthiness', Mode: 'healthiness',
@ -323,6 +329,7 @@ var Allocation = {
}, },
'group-dupe': { 'group-dupe': {
Check: 'is-alive', Check: 'is-alive',
Alloc: 'my-alloc',
Group: 'trying-multi-dupes.fakepy[1]', Group: 'trying-multi-dupes.fakepy[1]',
ID: 'group-dupe', ID: 'group-dupe',
Mode: 'healthiness', Mode: 'healthiness',
@ -333,6 +340,7 @@ var Allocation = {
}, },
'task-dupe': { 'task-dupe': {
Check: 'is-alive', Check: 'is-alive',
Alloc: 'my-alloc',
Group: 'trying-multi-dupes.fakepy[1]', Group: 'trying-multi-dupes.fakepy[1]',
ID: 'task-dupe', ID: 'task-dupe',
Mode: 'healthiness', Mode: 'healthiness',
@ -342,7 +350,7 @@ var Allocation = {
Timestamp: 1662131947, Timestamp: 1662131947,
}, },
}, },
id: 'my-alloc',
states: [ states: [
{ {
Name: 'http.server', Name: 'http.server',