-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4195 from hashicorp/b-ui-retry-stats-requests
UI: Retry stats requests
- Loading branch information
Showing
5 changed files
with
119 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export default function generateResources() { | ||
return { | ||
CpuStats: { | ||
Measured: ['Throttled Periods', 'Throttled Time', 'Percent'], | ||
Percent: 0.14159538847117795, | ||
SystemMode: 0, | ||
ThrottledPeriods: 0, | ||
ThrottledTime: 0, | ||
TotalTicks: 300.256693934837093, | ||
UserMode: 0, | ||
}, | ||
MemoryStats: { | ||
Cache: 1744896, | ||
KernelMaxUsage: 0, | ||
KernelUsage: 0, | ||
MaxUsage: 4710400, | ||
Measured: ['RSS', 'Cache', 'Swap', 'Max Usage'], | ||
RSS: 1486848009, | ||
Swap: 0, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { getOwner } from '@ember/application'; | ||
import { test, moduleForComponent } from 'ember-qunit'; | ||
import wait from 'ember-test-helpers/wait'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import generateResources from '../../mirage/data/generate-resources'; | ||
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; | ||
import Response from 'ember-cli-mirage/response'; | ||
|
||
moduleForComponent('allocation-row', 'Integration | Component | allocation row', { | ||
integration: true, | ||
beforeEach() { | ||
this.store = getOwner(this).lookup('service:store'); | ||
this.server = startMirage(); | ||
this.server.create('namespace'); | ||
this.server.create('node'); | ||
this.server.create('job', { createAllocations: false }); | ||
}, | ||
afterEach() { | ||
this.server.shutdown(); | ||
}, | ||
}); | ||
|
||
test('Allocation row polls for stats, even when it errors or has an invalid response', function(assert) { | ||
const component = this; | ||
|
||
let currentFrame = 0; | ||
let frames = [ | ||
JSON.stringify({ ResourceUsage: generateResources() }), | ||
JSON.stringify({ ResourceUsage: generateResources() }), | ||
null, | ||
'<Not>Valid JSON</Not>', | ||
JSON.stringify({ ResourceUsage: generateResources() }), | ||
]; | ||
const backoffSequence = [50]; | ||
|
||
this.server.get('/client/allocation/:id/stats', function() { | ||
const response = frames[++currentFrame]; | ||
|
||
// Disable polling to stop the EC task in the component | ||
if (currentFrame >= frames.length) { | ||
component.set('enablePolling', false); | ||
} | ||
|
||
if (response) { | ||
return response; | ||
} | ||
return new Response(500, {}, ''); | ||
}); | ||
|
||
this.server.create('allocation'); | ||
this.store.findAll('allocation'); | ||
|
||
let allocation; | ||
|
||
return wait() | ||
.then(() => { | ||
allocation = this.store.peekAll('allocation').get('firstObject'); | ||
|
||
this.setProperties({ | ||
allocation, | ||
backoffSequence, | ||
context: 'job', | ||
enablePolling: true, | ||
}); | ||
|
||
this.render(hbs` | ||
{{allocation-row | ||
allocation=allocation | ||
context=context | ||
backoffSequence=backoffSequence | ||
enablePolling=enablePolling}} | ||
`); | ||
return wait(); | ||
}) | ||
.then(() => { | ||
assert.equal( | ||
this.server.pretender.handledRequests.filterBy( | ||
'url', | ||
`/v1/client/allocation/${allocation.get('id')}/stats` | ||
).length, | ||
frames.length, | ||
'Requests continue to be made after malformed responses and server errors' | ||
); | ||
}); | ||
}); |