Skip to content

Commit

Permalink
fixed failing tests in the commands router
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed May 30, 2024
1 parent 8e06362 commit 967f78e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
3 changes: 3 additions & 0 deletions api/src/opentrons/protocol_runner/run_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,6 @@ async def add_command_and_wait_for_interval(self, command: CommandCreate, wait_u
with move_on_after(timeout_sec):
await self._protocol_engine.wait_for_command(added_command.id)
return added_command

def estop(self) -> None:
return self._protocol_engine.estop()
4 changes: 2 additions & 2 deletions robot-server/robot_server/runs/engine_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ async def handle_estop_event(engine_store: "EngineStore", event: HardwareEvent)
return
# todo(mm, 2024-04-17): This estop teardown sequencing belongs in the
# runner layer.
engine_store.engine.estop()
await engine_store.engine.finish(error=EStopActivatedError())
engine_store._run_orchestrator.estop()
await engine_store._run_orchestrator.finish(error=EStopActivatedError())
except Exception:
# This is a background task kicked off by a hardware event,
# so there's no one to propagate this exception to.
Expand Down
1 change: 1 addition & 0 deletions robot-server/robot_server/runs/router/commands_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ async def create_run_command(
# behavior is to pass through `command_intent` without overriding it
command_intent = request_body.data.intent or pe_commands.CommandIntent.SETUP
command_create = request_body.data.copy(update={"intent": command_intent})

try:
command = await engine_store.add_command_and_wait_for_interval(
request=command_create,
Expand Down
24 changes: 10 additions & 14 deletions robot-server/tests/runs/router/test_commands_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def _stub_queued_command_state(*_a: object, **_k: object) -> pe_commands.Command
params=pe_commands.WaitForResumeParams(message="Hello"),
intent=pe_commands.CommandIntent.SETUP,
),
wait_until_complete=False,
timeout=12,
failed_command_id=None,
)
).then_do(_stub_queued_command_state)
Expand All @@ -128,6 +130,7 @@ def _stub_queued_command_state(*_a: object, **_k: object) -> pe_commands.Command
waitUntilComplete=False,
engine_store=mock_engine_store,
failedCommandId=None,
timeout=12
)

assert result.content.data == command_once_added
Expand Down Expand Up @@ -188,23 +191,15 @@ async def test_create_run_command_blocking_completion(
result=pe_commands.WaitForResumeResult(),
)

def _stub_queued_command_state(*_a: object, **_k: object) -> pe_commands.Command:
decoy.when(mock_engine_store.get_command("command-id")).then_return(
command_once_added
)

return command_once_added

def _stub_completed_command_state(*_a: object, **_k: object) -> None:
decoy.when(mock_engine_store.get_command("command-id")).then_return(
command_once_completed
)

decoy.when(
await mock_engine_store.add_command_and_wait_for_interval(
request=command_request, failed_command_id=None
request=command_request, failed_command_id=None, wait_until_complete=True, timeout=999
)
).then_do(_stub_queued_command_state)
).then_do(command_once_completed)

decoy.when(mock_engine_store.get_command("command-id")).then_return(
command_once_completed
)

result = await create_run_command(
request_body=RequestModelWithCommandCreate(data=command_request),
Expand All @@ -214,6 +209,7 @@ def _stub_completed_command_state(*_a: object, **_k: object) -> None:
failedCommandId=None,
)

print(result.content.data)
assert result.content.data == command_once_completed
assert result.status_code == 201

Expand Down

0 comments on commit 967f78e

Please sign in to comment.