Skip to content

Commit

Permalink
Fix recommendation test to ensure CPU exists (#10004)
Browse files Browse the repository at this point in the history
This fixes a flaky test, as seen in this failure:
https://app.circleci.com/pipelines/github/hashicorp/nomad/14726/workflows/f4ae0bf2-0699-4d18-b55e-5221aafe393c/jobs/137128

One part of the test involves toggling off all memory recommendations
and then accepting, but it’s not possible to accept when there are
no CPU recommendations to begin with, which can happen because
there’s a 10% chance of not creating a corresponding recommendation
in the task factory. Since two tasks are created for this module, it’s
only a 1% chance of no CPU task, but that means 1% flakiness!
  • Loading branch information
backspace authored Feb 16, 2021
1 parent def4d61 commit cb4443d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions ui/tests/acceptance/optimize-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,26 @@ module('Acceptance | optimize', function(hooks) {
});

test('lets recommendations be toggled, reports the choices to the recommendations API, and displays task group recommendations serially', async function(assert) {
await Optimize.visit();

const currentTaskGroup = this.job1.taskGroups.models[0];
const nextTaskGroup = this.job2.taskGroups.models[0];

const currentTaskGroupHasCPURecommendation = currentTaskGroup.tasks.models
.mapBy('recommendations.models')
.flat()
.find(r => r.resource === 'CPU');

// If no CPU recommendation, will not be able to accept recommendation with all memory recommendations turned off

if (!currentTaskGroupHasCPURecommendation) {
const currentTaskGroupTask = currentTaskGroup.tasks.models[0];
this.server.create('recommendation', {
task: currentTaskGroupTask,
resource: 'CPU',
});
}

await Optimize.visit();

assert.equal(Layout.breadcrumbFor('optimize').text, 'Recommendations');

assert.equal(
Expand Down

0 comments on commit cb4443d

Please sign in to comment.