Skip to content

Commit

Permalink
fixed failing tests and added setup runner for default runner
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed May 14, 2024
1 parent 19fbee9 commit 5702c5c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
17 changes: 2 additions & 15 deletions api/src/opentrons/protocol_runner/run_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,9 @@ def add_command(
return self._json_or_python_runner.set_command_queued(request)

# TODO(tz, 2024-5-13): what runner should we return?
def get_protocol_runner(self) -> Optional[Union[protocol_runner.JsonRunner, protocol_runner.PythonAndLegacyRunner]]:
return self._json_or_python_runner
def get_protocol_runner(self) -> protocol_runner.AnyRunner:
return self._json_or_python_runner or self._setup_runner

def get_protocol_engine(self) -> ProtocolEngine:
return self._protocol_engine

async def load(
self,
protocol_source: ProtocolSource,
python_parse_mode: PythonParseMode,
run_time_param_values: Optional[RunTimeParamValuesType],
) -> None:
pass

def prepare(
self,
) -> None:
pass

16 changes: 7 additions & 9 deletions robot-server/robot_server/runs/engine_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,25 @@ async def create(
# concurrency hazard. If two requests simultaneously call this method,
# they will both "succeed" (with undefined results) instead of one
# raising EngineConflictError.
if isinstance(
self._run_orchestrator.get_protocol_runner(), PythonAndLegacyRunner
):
if isinstance(self.runner, PythonAndLegacyRunner):
assert (
protocol is not None
), "A Python protocol should have a protocol source file."
await self._run_orchestrator.load(
await self.runner.load(
protocol.source,
# Conservatively assume that we're re-running a protocol that
# was uploaded before we added stricter validation, and that
# doesn't conform to the new rules.
python_parse_mode=PythonParseMode.ALLOW_LEGACY_METADATA_AND_REQUIREMENTS,
run_time_param_values=run_time_param_values,
)
elif isinstance(self._run_orchestrator.get_protocol_runner(), JsonRunner):
elif isinstance(self.runner, JsonRunner):
assert (
protocol is not None
), "A JSON protocol should have a protocol source file."
await self._run_orchestrator.load(protocol.source)
await self.runner.load(protocol.source)
else:
self._run_orchestrator.prepare()
self.runner.prepare()

for offset in labware_offsets:
engine.add_labware_offset(offset)
Expand All @@ -295,8 +293,8 @@ async def clear(self) -> RunResult:
EngineConflictError: The current runner/engine pair is not idle, so
they cannot be cleared.
"""
engine = self._run_orchestrator.get_protocol_engine()
runner = self._run_orchestrator.get_protocol_runner()
engine = self.engine
runner = self.runner
if engine.state_view.commands.get_is_okay_to_clear():
await engine.finish(
drop_tips_after_run=False,
Expand Down
17 changes: 11 additions & 6 deletions robot-server/tests/runs/test_engine_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
from opentrons.hardware_control import HardwareControlAPI, API
from opentrons.hardware_control.types import EstopStateNotification, EstopState
from opentrons.protocol_engine import ProtocolEngine, StateSummary, types as pe_types
from opentrons.protocol_runner import (
RunResult,
LiveRunner,
JsonRunner,
)
from opentrons.protocol_runner import RunResult, LiveRunner, JsonRunner, RunOrchestrator
from opentrons.protocol_reader import ProtocolReader, ProtocolSource

from robot_server.protocols.protocol_store import ProtocolResource
Expand All @@ -25,13 +21,20 @@
NoRunnerEnginePairError,
handle_estop_event,
)
from robot_server.runs.run_models import Run


def mock_notify_publishers() -> None:
"""A mock notify_publishers."""
return None


@pytest.fixture
async def mock_run_orchestrator(decoy: Decoy) -> RunOrchestrator:
"""A mock RunOrchestrator"""
return decoy.mock(cls=RunOrchestrator)


@pytest.fixture
async def subject(decoy: Decoy, hardware_api: HardwareControlAPI) -> EngineStore:
"""Get a EngineStore test subject."""
Expand All @@ -53,7 +56,9 @@ async def json_protocol_source() -> ProtocolSource:
return await ProtocolReader().read_saved(files=[simple_protocol], directory=None)


async def test_create_engine(subject: EngineStore) -> None:
async def test_create_engine(
decoy: Decoy, subject: EngineStore, mock_run_orchestrator: RunOrchestrator
) -> None:
"""It should create an engine for a run."""
result = await subject.create(
run_id="run-id",
Expand Down

0 comments on commit 5702c5c

Please sign in to comment.