Skip to content

Commit

Permalink
Return current recovery target ID from StateView.
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxColoring committed May 20, 2024
1 parent ed298ab commit c56dc8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion api/src/opentrons/protocol_engine/state/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,13 @@ def get_all_commands_final(self) -> bool:

return no_command_running and no_command_to_execute

def get_recovery_target_id(self) -> Optional[str]:
"""Return the ID of the command currently undergoing error recovery, if any."""
return self._state.recovery_target_command_id

def get_recovery_in_progress_for_command(self, command_id: str) -> bool:
"""Return whether the given command failed and its error recovery is in progress."""
return self._state.recovery_target_command_id == command_id
return self.get_recovery_target_id() == command_id

def raise_fatal_command_error(self) -> None:
"""Raise the run's fatal command error, if there was one, as an exception.
Expand Down
10 changes: 7 additions & 3 deletions api/tests/opentrons/protocol_engine/state/test_command_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ def test_error_recovery_type_tracking() -> None:
assert view.get_error_recovery_type("c2") == ErrorRecoveryType.FAIL_RUN


def test_get_recovery_in_progress_for_command() -> None:
"""It should return whether error recovery is in progress for the given command."""
def test_recovery_target_tracking() -> None:
"""It should keep track of the command currently undergoing error recovery."""
subject = CommandStore(config=_make_config(), is_door_open=False)
subject_view = CommandView(subject.state)

Expand All @@ -382,12 +382,14 @@ def test_get_recovery_in_progress_for_command() -> None:
subject.handle_action(fail_1)

# c1 failed recoverably and we're currently recovering from it.
assert subject_view.get_recovery_target_id() == "c1"
assert subject_view.get_recovery_in_progress_for_command("c1")

resume_from_1_recovery = actions.ResumeFromRecoveryAction()
subject.handle_action(resume_from_1_recovery)

# c1 failed recoverably, but we've already completed its recovery.
assert subject_view.get_recovery_target_id() is None
assert not subject_view.get_recovery_in_progress_for_command("c1")

queue_2 = actions.QueueCommandAction(
Expand All @@ -411,6 +413,7 @@ def test_get_recovery_in_progress_for_command() -> None:
subject.handle_action(fail_2)

# c2 failed recoverably and we're currently recovering from it.
assert subject_view.get_recovery_target_id() == "c2"
assert subject_view.get_recovery_in_progress_for_command("c2")
# ...and that means we're *not* currently recovering from c1,
# even though it failed recoverably before.
Expand Down Expand Up @@ -439,7 +442,8 @@ def test_get_recovery_in_progress_for_command() -> None:
subject.handle_action(fail_3)

# c3 failed, but not recoverably.
assert not subject_view.get_recovery_in_progress_for_command("c2")
assert subject_view.get_recovery_target_id() is None
assert not subject_view.get_recovery_in_progress_for_command("c3")


def test_final_state_after_estop() -> None:
Expand Down

0 comments on commit c56dc8d

Please sign in to comment.