Repository: aurora Updated Branches: refs/heads/master ad86177a0 -> 6182bbfd2
Polling updates page if in progress in UI Reviewed at https://reviews.apache.org/r/63337/ Project: http://git-wip-us.apache.org/repos/asf/aurora/repo Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/6182bbfd Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/6182bbfd Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/6182bbfd Branch: refs/heads/master Commit: 6182bbfd2df6911b4acded81bc8644c7adc503e4 Parents: ad86177 Author: Reza Motamedi <[email protected]> Authored: Tue Nov 7 16:08:13 2017 -0800 Committer: David McLaughlin <[email protected]> Committed: Tue Nov 7 16:08:13 2017 -0800 ---------------------------------------------------------------------- ui/src/main/js/pages/Update.js | 13 ++++++ ui/src/main/js/pages/__tests__/Update-test.js | 52 +++++++++++++++++----- 2 files changed, 55 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aurora/blob/6182bbfd/ui/src/main/js/pages/Update.js ---------------------------------------------------------------------- diff --git a/ui/src/main/js/pages/Update.js b/ui/src/main/js/pages/Update.js index c900269..afe484e 100644 --- a/ui/src/main/js/pages/Update.js +++ b/ui/src/main/js/pages/Update.js @@ -5,6 +5,8 @@ import Loading from 'components/Loading'; import UpdateConfig from 'components/UpdateConfig'; import UpdateDetails from 'components/UpdateDetails'; +import { isInProgressUpdate } from 'utils/Update'; + export default class Update extends React.Component { constructor(props) { super(props); @@ -12,6 +14,17 @@ export default class Update extends React.Component { } componentWillMount() { + this.fetchUpdateDetails(); + } + + componentWillUpdate(nextProps, nextState) { + if (!nextState.loading && isInProgressUpdate(nextState.update)) { + // refetch update details in 60 seconds + setTimeout(() => { this.fetchUpdateDetails(); }, 60000); + } + } + + fetchUpdateDetails() { const { role, environment, name, uid } = this.props.match.params; const job = new JobKey(); http://git-wip-us.apache.org/repos/asf/aurora/blob/6182bbfd/ui/src/main/js/pages/__tests__/Update-test.js ---------------------------------------------------------------------- diff --git a/ui/src/main/js/pages/__tests__/Update-test.js b/ui/src/main/js/pages/__tests__/Update-test.js index 570a999..15cbb3b 100644 --- a/ui/src/main/js/pages/__tests__/Update-test.js +++ b/ui/src/main/js/pages/__tests__/Update-test.js @@ -20,20 +20,23 @@ const params = { function createMockApi(update) { const api = {}; - api.getJobUpdateDetails = (id, query, handler) => handler({ - result: { - getJobUpdateDetailsResult: { - detailsList: [update] + const mockGetJobUpdateDetails = jest.fn().mockImplementation( + (id, query, handler) => handler({ + result: { + getJobUpdateDetailsResult: { + detailsList: [update] + } + }, + serverInfo: { + clusterName: TEST_CLUSTER } - }, - serverInfo: { - clusterName: TEST_CLUSTER - } - }); + }) + ); + api.getJobUpdateDetails = mockGetJobUpdateDetails; return api; } -const update = {}; // only testing pass-through here... +const update = {update: {summary: {state: {status: JobUpdateStatus.ROLLING_FORWARD}}}}; describe('Update', () => { it('Should render Loading before data is fetched', () => { @@ -53,4 +56,33 @@ describe('Update', () => { expect(el.contains(<UpdateConfig update={update} />)).toBe(true); expect(el.contains(<UpdateDetails update={update} />)).toBe(true); }); + + it('Should poll an inprogress update in 60 seconds', () => { + jest.useFakeTimers(); + const apiSpy = createMockApi(update); + const el = shallow(<Update api={apiSpy} match={{params: params}} />, + { lifecycleExperimental: true }); + el.setState({update: update}); + + expect(setTimeout.mock.calls.length).toBe(1); + expect(setTimeout.mock.calls[0][1]).toBe(60000); + expect(apiSpy.getJobUpdateDetails.mock.calls.length).toBe(1); + + jest.runOnlyPendingTimers(); + expect(apiSpy.getJobUpdateDetails.mock.calls.length).toBe(2); + expect(setTimeout.mock.calls.length).toBe(2); + expect(setTimeout.mock.calls[1][1]).toBe(60000); + }); + + it('Should not poll when update is not inprogress', () => { + jest.useFakeTimers(); + const terminatedUpdate = {update: {summary: {state: {status: JobUpdateStatus.ABORTED}}}}; + const apiSpy = createMockApi(terminatedUpdate); + const el = shallow(<Update api={apiSpy} match={{params: params}} />, + { lifecycleExperimental: true }); + el.setState({update: terminatedUpdate}); + + expect(setTimeout.mock.calls.length).toBe(0); + expect(apiSpy.getJobUpdateDetails.mock.calls.length).toBe(1); + }); });
