From e013dc50ad0cee1b8d00045cfb581cf0a3c9f8cf Mon Sep 17 00:00:00 2001 From: curtelsasser Date: Tue, 25 May 2021 11:30:00 -0400 Subject: [PATCH 1/9] [7740] bug: Run timer stays at 00:00:00 if you reconnect in the middle of a delay: - introducing pause and paused duration support. Was going to refactor to use a `StopWatch` but it was so invasive and was intimidated away from that refactor. - need to follow up. Switching gears. --- api/src/opentrons/hardware_control/api.py | 5 +++- app/src/redux/robot/api-client/client.js | 4 +++- app/src/redux/robot/reducer/session.js | 28 +++++++++++++++++++---- app/src/redux/robot/selectors.js | 17 +++++++------- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/api/src/opentrons/hardware_control/api.py b/api/src/opentrons/hardware_control/api.py index 8fc4d6c38a4..6a5e6d0b6ae 100644 --- a/api/src/opentrons/hardware_control/api.py +++ b/api/src/opentrons/hardware_control/api.py @@ -338,7 +338,10 @@ async def delay(self, duration_s: float): await self._wait_for_is_running() self.pause(PauseType.DELAY) try: - if not self.is_simulator: + if self.is_simulator: + print(f'sleeping {duration_s/60} minutes') + await asyncio.sleep(duration_s) + else: async def sleep_for_seconds(seconds: float): await asyncio.sleep(seconds) delay_task = self._loop.create_task(sleep_for_seconds(duration_s)) diff --git a/app/src/redux/robot/api-client/client.js b/app/src/redux/robot/api-client/client.js index 6e1a46a7193..c30f5486844 100755 --- a/app/src/redux/robot/api-client/client.js +++ b/app/src/redux/robot/api-client/client.js @@ -429,7 +429,9 @@ export function client(dispatch) { function setRunTimerInterval() { if (runTimerInterval === NO_INTERVAL) { runTimerInterval = setInterval( - () => dispatch(actions.tickRunTime()), + () => { + dispatch(actions.tickRunTime()) + }, RUN_TIME_TICK_INTERVAL_MS ) } diff --git a/app/src/redux/robot/reducer/session.js b/app/src/redux/robot/reducer/session.js index 07ba0f0e571..ea4e147b6fe 100644 --- a/app/src/redux/robot/reducer/session.js +++ b/app/src/redux/robot/reducer/session.js @@ -57,6 +57,8 @@ export type SessionState = { remoteTimeCompensation: number | null, startTime: ?number, runTime: number, + pausedTime: number, + pausedDuration: number, apiLevel: [number, number] | null, capabilities: Array, } @@ -104,6 +106,8 @@ const INITIAL_STATE: SessionState = { remoteTimeCompensation: null, startTime: null, runTime: 0, + pausedTime: 0, + pausedDuration: 0, apiLevel: null, } @@ -111,6 +115,7 @@ export function sessionReducer( state: SessionState = INITIAL_STATE, action: Action ): SessionState { + console.log(`sessionReducer ${action.type}, action=`, action); switch (action.type) { case 'robot:CONNECT_RESPONSE': { if (action.payload.error) return state @@ -220,10 +225,15 @@ function handleSessionUpdate( } function handleSessionInProgress(state: SessionState): SessionState { + console.log('handleSessionInProgress', state); return { ...state, + // todo: ce - think we want to pick up where we left off? + pausedDuration: 0, + // todo: ce - think we want to pick up where we left off? runTime: 0, - startTime: null, + // todo: ce - think we want to pick up where we left off? + startTime: Date.now(), remoteTimeCompensation: null, sessionRequest: { inProgress: true, error: null }, } @@ -262,7 +272,7 @@ function handleInvalidFile( } function handleRun(state: SessionState, action: any): SessionState { - return { ...state, runTime: 0, runRequest: { inProgress: true, error: null } } + return { ...state, runTime: Date.now(), runRequest: { inProgress: true, error: null } } } function handleRunResponse(state: SessionState, action: any): SessionState { @@ -280,7 +290,11 @@ function handleTickRunTime(state: SessionState, action: any): SessionState { } function handlePause(state: SessionState, action: any): SessionState { - return { ...state, pauseRequest: { inProgress: true, error: null } } + return { ...state, + pausedTime: Date.now(), + pauseRequest: { inProgress: true, error: null }, + runTime: Date.now() + } } function handlePauseResponse(state: SessionState, action: any): SessionState { @@ -294,7 +308,13 @@ function handlePauseResponse(state: SessionState, action: any): SessionState { } function handleResume(state: SessionState, action: any): SessionState { - return { ...state, resumeRequest: { inProgress: true, error: null } } + const pausedDuration = state.pausedTime ? Date.now() - state.pausedTime : 0; + return { ...state, + pausedDuration: state.pausedDuration + pausedDuration, + pausedTime: 0, + resumeRequest: { inProgress: true, error: null }, + runTime: Date.now() + } } function handleResumeResponse(state: SessionState, action: any): SessionState { diff --git a/app/src/redux/robot/selectors.js b/app/src/redux/robot/selectors.js index c32d9f9f3f3..d7bc9ff3705 100644 --- a/app/src/redux/robot/selectors.js +++ b/app/src/redux/robot/selectors.js @@ -208,6 +208,7 @@ const getStartTimeMs = (state: State): number | null => { return null } + console.log(`getStartTimeMs ${remoteTimeCompensation}`); return startTime + remoteTimeCompensation } @@ -218,15 +219,13 @@ export const getStartTime: (state: State) => string | null = createSelector( } ) -export const getRunSeconds: State => number = createSelector( - getStartTimeMs, - (state: State) => session(state).runTime, - (startTime: ?number, runTime: ?number): number => { - return runTime && startTime && runTime > startTime - ? Math.floor((runTime - startTime) / 1000) - : 0 - } -) +export function getRunSeconds(state: State): number { + const {startTime, runTime, pausedDuration} = session(state); + console.log('getRunSeconds: ', {startTime, runTime, pausedDuration}); + return runTime && startTime && runTime > startTime + ? Math.floor((runTime - startTime - pausedDuration) / 1000) + : 0 +} export function formatSeconds(runSeconds: number): string { const hours = padStart(`${Math.floor(runSeconds / 3600)}`, 2, '0') From a7118b4872b482f4e484ac289c564a6d085352d3 Mon Sep 17 00:00:00 2001 From: curtelsasser Date: Wed, 26 May 2021 10:47:35 -0400 Subject: [PATCH 2/9] - have what may be a hacky fix. - lots of logging which will be removed - notes about the pause logic --- app/src/redux/robot/reducer/session.js | 8 ++++++++ app/src/redux/robot/selectors.js | 10 +++++----- app/src/rpc/client.js | 1 + app/src/rpc/websocket-client.js | 1 + 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/src/redux/robot/reducer/session.js b/app/src/redux/robot/reducer/session.js index ea4e147b6fe..c8e05a1e226 100644 --- a/app/src/redux/robot/reducer/session.js +++ b/app/src/redux/robot/reducer/session.js @@ -57,7 +57,15 @@ export type SessionState = { remoteTimeCompensation: number | null, startTime: ?number, runTime: number, + /** + * Set to `Date.now()` when session is paused. Set to `0` when session is resumed. + * todo? Managed locally. Lost if the app is re-loaded. How interested are we in this functionality? + */ pausedTime: number, + /** + * Updated after cycle of pause -> resume. + * todo? Managed locally. Lost if the app is re-loaded. How interested are we in this functionality? + */ pausedDuration: number, apiLevel: [number, number] | null, capabilities: Array, diff --git a/app/src/redux/robot/selectors.js b/app/src/redux/robot/selectors.js index d7bc9ff3705..f5a1242c2f7 100644 --- a/app/src/redux/robot/selectors.js +++ b/app/src/redux/robot/selectors.js @@ -203,13 +203,13 @@ export const getSessionError: State => string | null = createSelector( const getStartTimeMs = (state: State): number | null => { const { startTime, remoteTimeCompensation } = session(state) - - if (startTime == null || remoteTimeCompensation === null) { + if (startTime == null) { return null } - - console.log(`getStartTimeMs ${remoteTimeCompensation}`); - return startTime + remoteTimeCompensation + // [7740] ce: 5/26/2021 - upon reload `remoteTimeCompensation` is null. + // will look to see why, but in the meantime this solves the start-time + // issue on reload but may create other issues? + return startTime + remoteTimeCompensation || 0 } export const getStartTime: (state: State) => string | null = createSelector( diff --git a/app/src/rpc/client.js b/app/src/rpc/client.js index a9b892deadb..8fb91784e90 100644 --- a/app/src/rpc/client.js +++ b/app/src/rpc/client.js @@ -214,6 +214,7 @@ class RpcContext extends EventEmitter { // then cache its type object this._cacheCallResultMetadata(root) this._cacheCallResultMetadata(rootType) + console.log('_handleMessage', this._resultTypes, this._typeObjectCache); if (meta.monitor) this._startMonitoring() diff --git a/app/src/rpc/websocket-client.js b/app/src/rpc/websocket-client.js index a89845efb4c..29a24d843d2 100644 --- a/app/src/rpc/websocket-client.js +++ b/app/src/rpc/websocket-client.js @@ -8,6 +8,7 @@ function parseMessage(data) { try { message = JSON.parse(data) + console.log(`rpc.parseMessage: ${data}`); } catch (e) { console.warn('JSON parse error', e) } From 2ecf85b2d5f735a33733a4d74083a957fc5a15e5 Mon Sep 17 00:00:00 2001 From: curtelsasser Date: Wed, 26 May 2021 16:02:00 -0400 Subject: [PATCH 3/9] - removing debugging aids --- api/src/opentrons/hardware_control/api.py | 5 +---- app/src/redux/robot/api-client/client.js | 4 +--- app/src/redux/robot/reducer/session.js | 13 ++++--------- app/src/redux/robot/selectors.js | 4 ++-- app/src/rpc/client.js | 1 - app/src/rpc/websocket-client.js | 1 - 6 files changed, 8 insertions(+), 20 deletions(-) diff --git a/api/src/opentrons/hardware_control/api.py b/api/src/opentrons/hardware_control/api.py index 8233c3e3ab6..470de86a949 100644 --- a/api/src/opentrons/hardware_control/api.py +++ b/api/src/opentrons/hardware_control/api.py @@ -339,10 +339,7 @@ async def delay(self, duration_s: float): await self._wait_for_is_running() self.pause(PauseType.DELAY) try: - if self.is_simulator: - print(f'sleeping {duration_s/60} minutes') - await asyncio.sleep(duration_s) - else: + if not self.is_simulator: async def sleep_for_seconds(seconds: float): await asyncio.sleep(seconds) delay_task = self._loop.create_task(sleep_for_seconds(duration_s)) diff --git a/app/src/redux/robot/api-client/client.js b/app/src/redux/robot/api-client/client.js index c30f5486844..6e1a46a7193 100755 --- a/app/src/redux/robot/api-client/client.js +++ b/app/src/redux/robot/api-client/client.js @@ -429,9 +429,7 @@ export function client(dispatch) { function setRunTimerInterval() { if (runTimerInterval === NO_INTERVAL) { runTimerInterval = setInterval( - () => { - dispatch(actions.tickRunTime()) - }, + () => dispatch(actions.tickRunTime()), RUN_TIME_TICK_INTERVAL_MS ) } diff --git a/app/src/redux/robot/reducer/session.js b/app/src/redux/robot/reducer/session.js index c8e05a1e226..474103ae3aa 100644 --- a/app/src/redux/robot/reducer/session.js +++ b/app/src/redux/robot/reducer/session.js @@ -58,13 +58,13 @@ export type SessionState = { startTime: ?number, runTime: number, /** - * Set to `Date.now()` when session is paused. Set to `0` when session is resumed. - * todo? Managed locally. Lost if the app is re-loaded. How interested are we in this functionality? + * Used to calculate the `pausedTimer` + * todo: Managed locally? Lost if the app is re-loaded. How interested are we in this functionality? */ pausedTime: number, /** * Updated after cycle of pause -> resume. - * todo? Managed locally. Lost if the app is re-loaded. How interested are we in this functionality? + * todo: Managed locally? Lost if the app is re-loaded. How interested are we in this functionality? */ pausedDuration: number, apiLevel: [number, number] | null, @@ -123,7 +123,6 @@ export function sessionReducer( state: SessionState = INITIAL_STATE, action: Action ): SessionState { - console.log(`sessionReducer ${action.type}, action=`, action); switch (action.type) { case 'robot:CONNECT_RESPONSE': { if (action.payload.error) return state @@ -233,15 +232,11 @@ function handleSessionUpdate( } function handleSessionInProgress(state: SessionState): SessionState { - console.log('handleSessionInProgress', state); return { ...state, - // todo: ce - think we want to pick up where we left off? pausedDuration: 0, - // todo: ce - think we want to pick up where we left off? runTime: 0, - // todo: ce - think we want to pick up where we left off? - startTime: Date.now(), + startTime: null, remoteTimeCompensation: null, sessionRequest: { inProgress: true, error: null }, } diff --git a/app/src/redux/robot/selectors.js b/app/src/redux/robot/selectors.js index f5a1242c2f7..bbd52fbc8c6 100644 --- a/app/src/redux/robot/selectors.js +++ b/app/src/redux/robot/selectors.js @@ -220,8 +220,8 @@ export const getStartTime: (state: State) => string | null = createSelector( ) export function getRunSeconds(state: State): number { - const {startTime, runTime, pausedDuration} = session(state); - console.log('getRunSeconds: ', {startTime, runTime, pausedDuration}); + const startTime = getStartTimeMs(state); + const {runTime, pausedDuration} = session(state); return runTime && startTime && runTime > startTime ? Math.floor((runTime - startTime - pausedDuration) / 1000) : 0 diff --git a/app/src/rpc/client.js b/app/src/rpc/client.js index 8fb91784e90..a9b892deadb 100644 --- a/app/src/rpc/client.js +++ b/app/src/rpc/client.js @@ -214,7 +214,6 @@ class RpcContext extends EventEmitter { // then cache its type object this._cacheCallResultMetadata(root) this._cacheCallResultMetadata(rootType) - console.log('_handleMessage', this._resultTypes, this._typeObjectCache); if (meta.monitor) this._startMonitoring() diff --git a/app/src/rpc/websocket-client.js b/app/src/rpc/websocket-client.js index 29a24d843d2..a89845efb4c 100644 --- a/app/src/rpc/websocket-client.js +++ b/app/src/rpc/websocket-client.js @@ -8,7 +8,6 @@ function parseMessage(data) { try { message = JSON.parse(data) - console.log(`rpc.parseMessage: ${data}`); } catch (e) { console.warn('JSON parse error', e) } From 1c9db9a9b29b639a78ed6b4edce9894f2170f35c Mon Sep 17 00:00:00 2001 From: curtelsasser Date: Wed, 26 May 2021 16:33:13 -0400 Subject: [PATCH 4/9] - removing debugging aids - clarify in comments - revise/add testing --- app/src/redux/robot/reducer/session.js | 8 +++-- app/src/redux/robot/test/selectors.test.js | 40 +++++++++++++++------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/app/src/redux/robot/reducer/session.js b/app/src/redux/robot/reducer/session.js index 474103ae3aa..dd36a459e1b 100644 --- a/app/src/redux/robot/reducer/session.js +++ b/app/src/redux/robot/reducer/session.js @@ -58,13 +58,15 @@ export type SessionState = { startTime: ?number, runTime: number, /** - * Used to calculate the `pausedTimer` - * todo: Managed locally? Lost if the app is re-loaded. How interested are we in this functionality? + * Used to calculate the `pausedDuration` + * todo: hacky in that it is managed locally. Not part of the start-time fix, + * but partially fixes issue of pausing without pausing the timer. Keep? */ pausedTime: number, /** * Updated after cycle of pause -> resume. - * todo: Managed locally? Lost if the app is re-loaded. How interested are we in this functionality? + * todo: hacky in that it is managed locally. Not part of the start-time fix, + * but partially fixes issue of pausing without pausing the timer. Keep? */ pausedDuration: number, apiLevel: [number, number] | null, diff --git a/app/src/redux/robot/test/selectors.test.js b/app/src/redux/robot/test/selectors.test.js index 314fc47f047..aeb97f0d4af 100644 --- a/app/src/redux/robot/test/selectors.test.js +++ b/app/src/redux/robot/test/selectors.test.js @@ -218,6 +218,7 @@ describe('robot selectors', () => { const state = { robot: { session: { + pausedDuration: 0, startTime: null, runTime: 42, }, @@ -227,28 +228,41 @@ describe('robot selectors', () => { expect(getRunTime(state)).toEqual('00:00:00') }) - it('getRunTime with no remoteTimeCompensation', () => { - const state = { - robot: { - session: { - remoteTimeCompensation: null, - startTime: 40, - runTime: 42, + it('getRunTime without remoteTimeCompensation', () => { + const testGetRunTime = (seconds, expected) => { + const stateWithRunTime = { + robot: { + session: { + pausedDuration: 0, + remoteTimeCompensation: null, + startTime: 40, + runTime: 42 + 1000 * seconds, + }, }, - }, + } + + expect(getRunTime(stateWithRunTime)).toEqual(expected) } - expect(getRunTime(state)).toEqual('00:00:00') + testGetRunTime(0, '00:00:00') + testGetRunTime(1, '00:00:01') + testGetRunTime(59, '00:00:59') + testGetRunTime(60, '00:01:00') + testGetRunTime(61, '00:01:01') + testGetRunTime(3599, '00:59:59') + testGetRunTime(3600, '01:00:00') + testGetRunTime(3601, '01:00:01') }) - it('getRunTime', () => { + it('getRunTime with remoteTimeCompensation', () => { const testGetRunTime = (seconds, expected) => { const stateWithRunTime = { robot: { session: { - remoteTimeCompensation: 0, - startTime: 42, - runTime: 42 + 1000 * seconds, + pausedDuration: 0, + remoteTimeCompensation: 1000, + startTime: 40, + runTime: 1042 + 1000 * seconds, }, }, } From e50b7f1eeb1c5a8ffc7b0d200171cd19b56899a0 Mon Sep 17 00:00:00 2001 From: curtelsasser Date: Wed, 26 May 2021 17:00:56 -0400 Subject: [PATCH 5/9] - fixing tests --- app/src/redux/robot/test/session-reducer.test.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/redux/robot/test/session-reducer.test.js b/app/src/redux/robot/test/session-reducer.test.js index 169285c2dbe..b5ddae8c44b 100644 --- a/app/src/redux/robot/test/session-reducer.test.js +++ b/app/src/redux/robot/test/session-reducer.test.js @@ -43,6 +43,8 @@ describe('robot reducer - session', () => { startTime: null, runTime: 0, apiLevel: null, + pausedDuration: 0, + pausedTime: 0, }) }) @@ -113,6 +115,7 @@ describe('robot reducer - session', () => { remoteTimeCompensation: null, startTime: null, runTime: 0, + pausedDuration: 0, }) }) @@ -198,7 +201,6 @@ describe('robot reducer - session', () => { it('handles RUN action', () => { const state = { session: { - runTime: now, runRequest: { inProgress: false, error: new Error('AH') }, }, } @@ -206,7 +208,7 @@ describe('robot reducer - session', () => { expect(reducer(state, action).session).toEqual({ runRequest: { inProgress: true, error: null }, - runTime: 0, + runTime: now, }) }) @@ -248,7 +250,9 @@ describe('robot reducer - session', () => { const action = { type: actionTypes.PAUSE } expect(reducer(state, action).session).toEqual({ + pausedTime: now, pauseRequest: { inProgress: true, error: null }, + runTime: now, }) }) @@ -281,13 +285,18 @@ describe('robot reducer - session', () => { it('handles RESUME action', () => { const state = { session: { + pausedDuration: 0, + pausedTime: now - 1000, resumeRequest: { inProgress: false, error: new Error('AH') }, }, } const action = { type: actionTypes.RESUME } expect(reducer(state, action).session).toEqual({ + pausedDuration: 1000, + pausedTime: 0, resumeRequest: { inProgress: true, error: null }, + runTime: now, }) }) From 95dc94de4bbcd6f988e404e1b97e29eff34838a9 Mon Sep 17 00:00:00 2001 From: curtelsasser Date: Wed, 26 May 2021 17:15:01 -0400 Subject: [PATCH 6/9] - prettifying --- app/src/redux/robot/reducer/session.js | 18 ++++++++++++------ app/src/redux/robot/selectors.js | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/redux/robot/reducer/session.js b/app/src/redux/robot/reducer/session.js index dd36a459e1b..6be31782597 100644 --- a/app/src/redux/robot/reducer/session.js +++ b/app/src/redux/robot/reducer/session.js @@ -277,7 +277,11 @@ function handleInvalidFile( } function handleRun(state: SessionState, action: any): SessionState { - return { ...state, runTime: Date.now(), runRequest: { inProgress: true, error: null } } + return { + ...state, + runTime: Date.now(), + runRequest: { inProgress: true, error: null }, + } } function handleRunResponse(state: SessionState, action: any): SessionState { @@ -295,10 +299,11 @@ function handleTickRunTime(state: SessionState, action: any): SessionState { } function handlePause(state: SessionState, action: any): SessionState { - return { ...state, + return { + ...state, pausedTime: Date.now(), pauseRequest: { inProgress: true, error: null }, - runTime: Date.now() + runTime: Date.now(), } } @@ -313,12 +318,13 @@ function handlePauseResponse(state: SessionState, action: any): SessionState { } function handleResume(state: SessionState, action: any): SessionState { - const pausedDuration = state.pausedTime ? Date.now() - state.pausedTime : 0; - return { ...state, + const pausedDuration = state.pausedTime ? Date.now() - state.pausedTime : 0 + return { + ...state, pausedDuration: state.pausedDuration + pausedDuration, pausedTime: 0, resumeRequest: { inProgress: true, error: null }, - runTime: Date.now() + runTime: Date.now(), } } diff --git a/app/src/redux/robot/selectors.js b/app/src/redux/robot/selectors.js index bbd52fbc8c6..88629479276 100644 --- a/app/src/redux/robot/selectors.js +++ b/app/src/redux/robot/selectors.js @@ -220,8 +220,8 @@ export const getStartTime: (state: State) => string | null = createSelector( ) export function getRunSeconds(state: State): number { - const startTime = getStartTimeMs(state); - const {runTime, pausedDuration} = session(state); + const startTime = getStartTimeMs(state) + const { runTime, pausedDuration } = session(state) return runTime && startTime && runTime > startTime ? Math.floor((runTime - startTime - pausedDuration) / 1000) : 0 From 43af7b1678c4a583f38d22a9aba77253512a0348 Mon Sep 17 00:00:00 2001 From: curtelsasser Date: Wed, 26 May 2021 17:27:48 -0400 Subject: [PATCH 7/9] - more enduring fix --- app/src/redux/robot/selectors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/redux/robot/selectors.js b/app/src/redux/robot/selectors.js index 88629479276..3bd1e01f859 100644 --- a/app/src/redux/robot/selectors.js +++ b/app/src/redux/robot/selectors.js @@ -222,8 +222,8 @@ export const getStartTime: (state: State) => string | null = createSelector( export function getRunSeconds(state: State): number { const startTime = getStartTimeMs(state) const { runTime, pausedDuration } = session(state) - return runTime && startTime && runTime > startTime - ? Math.floor((runTime - startTime - pausedDuration) / 1000) + return runTime && startTime + ? Math.max(0, Math.floor((runTime - startTime - pausedDuration) / 1000)) : 0 } From 3d59ea71231313af446af4d5cf7f7a0b22119051 Mon Sep 17 00:00:00 2001 From: curtelsasser Date: Fri, 28 May 2021 10:38:21 -0400 Subject: [PATCH 8/9] - update pause[purpose] property documentation with Max's better summarization. And being more consistent with startTime and making pauseTime be `null` when not activated. --- app/src/redux/robot/reducer/session.js | 12 ++++++------ app/src/redux/robot/test/session-reducer.test.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/redux/robot/reducer/session.js b/app/src/redux/robot/reducer/session.js index 6be31782597..73719a01500 100644 --- a/app/src/redux/robot/reducer/session.js +++ b/app/src/redux/robot/reducer/session.js @@ -58,17 +58,17 @@ export type SessionState = { startTime: ?number, runTime: number, /** - * Used to calculate the `pausedDuration` + * The total number of seconds that this protocol has spent paused, across all steps executed so far. * todo: hacky in that it is managed locally. Not part of the start-time fix, * but partially fixes issue of pausing without pausing the timer. Keep? */ - pausedTime: number, + pausedDuration: number, /** - * Updated after cycle of pause -> resume. + * When paused it is the time at which protocol execution pause was started. When not paused it is null. * todo: hacky in that it is managed locally. Not part of the start-time fix, * but partially fixes issue of pausing without pausing the timer. Keep? */ - pausedDuration: number, + pausedTime: number | null, apiLevel: [number, number] | null, capabilities: Array, } @@ -116,7 +116,7 @@ const INITIAL_STATE: SessionState = { remoteTimeCompensation: null, startTime: null, runTime: 0, - pausedTime: 0, + pausedTime: null, pausedDuration: 0, apiLevel: null, } @@ -322,7 +322,7 @@ function handleResume(state: SessionState, action: any): SessionState { return { ...state, pausedDuration: state.pausedDuration + pausedDuration, - pausedTime: 0, + pausedTime: null, resumeRequest: { inProgress: true, error: null }, runTime: Date.now(), } diff --git a/app/src/redux/robot/test/session-reducer.test.js b/app/src/redux/robot/test/session-reducer.test.js index b5ddae8c44b..ce6e79afc13 100644 --- a/app/src/redux/robot/test/session-reducer.test.js +++ b/app/src/redux/robot/test/session-reducer.test.js @@ -44,7 +44,7 @@ describe('robot reducer - session', () => { runTime: 0, apiLevel: null, pausedDuration: 0, - pausedTime: 0, + pausedTime: null, }) }) @@ -294,7 +294,7 @@ describe('robot reducer - session', () => { expect(reducer(state, action).session).toEqual({ pausedDuration: 1000, - pausedTime: 0, + pausedTime: null, resumeRequest: { inProgress: true, error: null }, runTime: now, }) From 073967c1bf7f03a920df9322438ff480fb4242a2 Mon Sep 17 00:00:00 2001 From: curtelsasser Date: Fri, 28 May 2021 13:01:02 -0400 Subject: [PATCH 9/9] - very perplexed by tsc constraint observations --- app/src/redux/robot/reducer/session.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/redux/robot/reducer/session.js b/app/src/redux/robot/reducer/session.js index 73719a01500..b0eba46beff 100644 --- a/app/src/redux/robot/reducer/session.js +++ b/app/src/redux/robot/reducer/session.js @@ -318,7 +318,8 @@ function handlePauseResponse(state: SessionState, action: any): SessionState { } function handleResume(state: SessionState, action: any): SessionState { - const pausedDuration = state.pausedTime ? Date.now() - state.pausedTime : 0 + const pausedDuration = + state.pausedTime === null ? 0 : Date.now() - Number(state.pausedTime) return { ...state, pausedDuration: state.pausedDuration + pausedDuration,