Skip to content

Commit

Permalink
ci: fix some flaky UI tests (#17648)
Browse files Browse the repository at this point in the history
These tests would fail depending on the value of the seed used.
  • Loading branch information
lgfa29 committed Jun 22, 2023
1 parent 51ed353 commit 527192f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
29 changes: 15 additions & 14 deletions ui/tests/acceptance/allocation-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
/* Mirage fixtures are random so we can't expect a set number of assertions */
import AdapterError from '@ember-data/adapter/error';
import { run } from '@ember/runloop';
import {
currentURL,
click,
visit,
triggerEvent,
waitFor,
} from '@ember/test-helpers';
import { currentURL, click, triggerEvent, waitFor } from '@ember/test-helpers';
import { assign } from '@ember/polyfills';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down Expand Up @@ -683,7 +677,10 @@ module('Acceptance | allocation detail (services)', function (hooks) {
namespaceId: 'default',
});

const currentAlloc = server.db.allocations.findBy({ jobId: job.id });
const runningAlloc = server.create('allocation', {
jobId: job.id,
forceRunningClientStatus: true,
});
const otherAlloc = server.db.allocations.reject((j) => j.jobId !== job.id);

server.db.serviceFragments.update({
Expand All @@ -692,7 +689,7 @@ module('Acceptance | allocation detail (services)', function (hooks) {
Status: 'success',
Check: 'check1',
Timestamp: 99,
Alloc: currentAlloc.id,
Alloc: runningAlloc.id,
},
{
Status: 'failure',
Expand All @@ -701,21 +698,21 @@ module('Acceptance | allocation detail (services)', function (hooks) {
propThatDoesntMatter:
'this object will be ignored, since it shared a Check name with a later one.',
Timestamp: 98,
Alloc: currentAlloc.id,
Alloc: runningAlloc.id,
},
{
Status: 'success',
Check: 'check2',
Output: 'Two',
Timestamp: 99,
Alloc: currentAlloc.id,
Alloc: runningAlloc.id,
},
{
Status: 'failure',
Check: 'check3',
Output: 'Oh no!',
Timestamp: 99,
Alloc: currentAlloc.id,
Alloc: runningAlloc.id,
},
{
Status: 'success',
Expand All @@ -731,14 +728,18 @@ module('Acceptance | allocation detail (services)', function (hooks) {
});

test('Allocation has a list of services with active checks', async function (assert) {
await visit('jobs/service-haver@default');
await click('.allocation-row');
const runningAlloc = server.db.allocations.findBy({
jobId: 'service-haver',
clientStatus: 'running',
});
await Allocation.visit({ id: runningAlloc.id });
assert.dom('[data-test-service]').exists();
assert.dom('.service-sidebar').exists();
assert.dom('.service-sidebar').doesNotHaveClass('open');
assert
.dom('[data-test-service-status-bar]')
.exists('At least one allocation has service health');

await click('[data-test-service-status-bar]');
assert.dom('.service-sidebar').hasClass('open');
assert
Expand Down
37 changes: 28 additions & 9 deletions ui/tests/acceptance/token-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,22 +636,28 @@ module('Acceptance | tokens', function (hooks) {

test('Tokens Deletion', async function (assert) {
allScenarios.policiesTestCluster(server);
const testPolicy = server.db.policies[0];
const existingTokens = server.db.tokens.filter((t) =>
t.policyIds.includes(testPolicy.name)
);
// Create an expired token
server.create('token', {
name: 'Doomed Token',
id: 'enjoying-my-day-here',
policyIds: [server.db.policies[0].name],
policyIds: [testPolicy.name],
});

window.localStorage.nomadTokenSecret = server.db.tokens[0].secretId;
await visit('/policies');

await click('[data-test-policy-row]:first-child');
assert.equal(currentURL(), `/policies/${server.db.policies[0].name}`);

assert.equal(currentURL(), `/policies/${testPolicy.name}`);
assert
.dom('[data-test-policy-token-row]')
.exists({ count: 3 }, 'Expected number of tokens are shown');
.exists(
{ count: existingTokens.length + 1 },
'Expected number of tokens are shown'
);

const doomedTokenRow = [...findAll('[data-test-policy-token-row]')].find(
(a) => a.textContent.includes('Doomed Token')
Expand All @@ -667,32 +673,45 @@ module('Acceptance | tokens', function (hooks) {
assert.dom('.flash-message.alert-success').exists();
assert
.dom('[data-test-policy-token-row]')
.exists({ count: 2 }, 'One fewer token after deletion');
.exists(
{ count: existingTokens.length },
'One fewer token after deletion'
);
await percySnapshot(assert);
window.localStorage.nomadTokenSecret = null;
});

test('Test Token Creation', async function (assert) {
allScenarios.policiesTestCluster(server);
const testPolicy = server.db.policies[0];
const existingTokens = server.db.tokens.filter((t) =>
t.policyIds.includes(testPolicy.name)
);

window.localStorage.nomadTokenSecret = server.db.tokens[0].secretId;
await visit('/policies');

await click('[data-test-policy-row]:first-child');
assert.equal(currentURL(), `/policies/${server.db.policies[0].name}`);
assert.equal(currentURL(), `/policies/${testPolicy.name}`);

assert
.dom('[data-test-policy-token-row]')
.exists({ count: 2 }, 'Expected number of tokens are shown');
.exists(
{ count: existingTokens.length },
'Expected number of tokens are shown'
);

await click('[data-test-create-test-token]');
assert.dom('.flash-message.alert-success').exists();
assert
.dom('[data-test-policy-token-row]')
.exists({ count: 3 }, 'One more token after test token creation');
.exists(
{ count: existingTokens.length + 1 },
'One more token after test token creation'
);
assert
.dom('[data-test-policy-token-row]:last-child [data-test-token-name]')
.hasText(`Example Token for ${server.db.policies[0].name}`);
.hasText(`Example Token for ${testPolicy.name}`);
await percySnapshot(assert);
window.localStorage.nomadTokenSecret = null;
});
Expand Down

0 comments on commit 527192f

Please sign in to comment.