Skip to content

Commit

Permalink
fix(api): stop-requested hanging on stop when awaiting-recovery (#15066)
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri authored May 1, 2024
1 parent 4635d72 commit 6e3c0d1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/src/opentrons/protocol_engine/state/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ def handle_action(self, action: Action) -> None: # noqa: C901

elif isinstance(action, StopAction):
if not self._state.run_result:
if self._state.queue_status == QueueStatus.AWAITING_RECOVERY:
self._state.recovery_target_command_id = None

self._state.queue_status = QueueStatus.PAUSED
if action.from_estop:
self._state.stopped_by_estop = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,41 @@ def test_command_store_handles_stop_action(
assert subject.state.command_history.get_setup_queue_ids() == OrderedSet()


def test_command_store_handles_stop_action_when_awaiting_recovery() -> None:
"""It should mark the engine as non-gracefully stopped on StopAction."""
subject = CommandStore(is_door_open=False, config=_make_config())

subject.handle_action(
PlayAction(
requested_at=datetime(year=2021, month=1, day=1), deck_configuration=[]
)
)

subject.state.queue_status = QueueStatus.AWAITING_RECOVERY

subject.handle_action(StopAction())

assert subject.state == CommandState(
command_history=CommandHistory(),
queue_status=QueueStatus.PAUSED,
run_result=RunResult.STOPPED,
run_completed_at=None,
is_door_blocking=False,
run_error=None,
finish_error=None,
failed_command=None,
command_error_recovery_types={},
recovery_target_command_id=None,
run_started_at=datetime(year=2021, month=1, day=1),
latest_protocol_command_hash=None,
stopped_by_estop=False,
)
assert subject.state.command_history.get_running_command() is None
assert subject.state.command_history.get_all_ids() == []
assert subject.state.command_history.get_queue_ids() == OrderedSet()
assert subject.state.command_history.get_setup_queue_ids() == OrderedSet()


def test_command_store_cannot_restart_after_should_stop() -> None:
"""It should reject a play action after finish."""
subject = CommandStore(is_door_open=False, config=_make_config())
Expand Down

0 comments on commit 6e3c0d1

Please sign in to comment.