Skip to content

Commit

Permalink
Fix job recommendation test flakiness (#9591)
Browse files Browse the repository at this point in the history
Instead of creating recommendations for all the jobs used
across these tests, this creates a specific job with
a higher group count, which reduces the likelihood
of having no recommendations to 0.0001%.

It was incorrect to assume that each task group would always
have recommendations, since there’s a 1% chance that a task
won’t have a recommendation. (10% chance for CPU and memory.)
This uses the number of groups with recommendations instead.
  • Loading branch information
backspace authored Dec 10, 2020
1 parent 7747124 commit 863c194
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions ui/tests/acceptance/job-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,9 @@ module('Acceptance | job detail (with namespaces)', function(hooks) {
type: 'service',
status: 'running',
namespaceId: server.db.namespaces[1].name,
createRecommendations: true,
});
server.createList('job', 3, {
namespaceId: server.db.namespaces[0].name,
createRecommendations: true,
});

managementToken = server.create('token');
Expand Down Expand Up @@ -214,14 +212,29 @@ module('Acceptance | job detail (with namespaces)', function(hooks) {
test('resource recommendations show when they exist and can be expanded, collapsed, and processed', async function(assert) {
server.create('feature', { name: 'Dynamic Application Sizing' });

job = server.create('job', {
type: 'service',
status: 'running',
namespaceId: server.db.namespaces[1].name,
groupsCount: 3,
createRecommendations: true,
});

window.localStorage.nomadTokenSecret = managementToken.secretId;
await JobDetail.visit({ id: job.id, namespace: server.db.namespaces[1].name });

assert.equal(JobDetail.recommendations.length, job.taskGroups.length);
const groupsWithRecommendations = job.taskGroups.filter(group =>
group.tasks.models.any(task => task.recommendations.models.length)
);
const jobRecommendationCount = groupsWithRecommendations.length;

const firstRecommendationGroup = groupsWithRecommendations.models[0];

assert.equal(JobDetail.recommendations.length, jobRecommendationCount);

const recommendation = JobDetail.recommendations[0];

assert.equal(recommendation.group, job.taskGroups.models[0].name);
assert.equal(recommendation.group, firstRecommendationGroup.name);
assert.ok(recommendation.card.isHidden);

const toggle = recommendation.toggleButton;
Expand All @@ -239,16 +252,16 @@ module('Acceptance | job detail (with namespaces)', function(hooks) {

await toggle.click();

assert.equal(recommendation.card.slug.groupName, job.taskGroups.models[0].name);
assert.equal(recommendation.card.slug.groupName, firstRecommendationGroup.name);

await recommendation.card.acceptButton.click();

assert.equal(JobDetail.recommendations.length, job.taskGroups.length - 1);
assert.equal(JobDetail.recommendations.length, jobRecommendationCount - 1);

await JobDetail.tabFor('definition').visit();
await JobDetail.tabFor('overview').visit();

assert.equal(JobDetail.recommendations.length, job.taskGroups.length - 1);
assert.equal(JobDetail.recommendations.length, jobRecommendationCount - 1);
});

test('resource recommendations are not fetched when the feature doesn’t exist', async function(assert) {
Expand All @@ -258,8 +271,7 @@ module('Acceptance | job detail (with namespaces)', function(hooks) {
assert.equal(JobDetail.recommendations.length, 0);

assert.equal(
server.pretender.handledRequests
.filter(request => request.url.includes('recommendations'))
server.pretender.handledRequests.filter(request => request.url.includes('recommendations'))
.length,
0
);
Expand Down

0 comments on commit 863c194

Please sign in to comment.