Skip to content

Commit 503dc95

Browse files
authored
fix(api): ensure correct sync hardware API is used for analysis (#11227)
RSS-11
1 parent 99a8d0b commit 503dc95

File tree

5 files changed

+67
-21
lines changed

5 files changed

+67
-21
lines changed

api/src/opentrons/protocol_runner/create_simulating_runner.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
"""Simulating ProtocolRunner factory."""
22

33
from opentrons.config import feature_flags
4-
from opentrons.hardware_control import (
5-
API as HardwareAPI,
6-
SynchronousAdapter,
7-
HardwareControlAPI,
8-
)
4+
from opentrons.hardware_control import API as HardwareAPI, HardwareControlAPI
95
from opentrons.protocol_engine import EngineConfigs, create_protocol_engine
106

117
from .legacy_wrappers import LegacySimulatingContextCreator
@@ -63,7 +59,7 @@ async def create_simulating_runner() -> ProtocolRunner:
6359

6460
simulating_legacy_context_creator = (
6561
LegacySimulatingContextCreator(
66-
sync_hardware_api=SynchronousAdapter(simulating_hardware_api),
62+
hardware_api=simulating_hardware_api,
6763
labware_offset_provider=offset_provider,
6864
)
6965
if not feature_flags.disable_fast_protocol_upload()

api/src/opentrons/protocol_runner/legacy_wrappers.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
from opentrons.calibration_storage.helpers import uri_from_details
1010

11-
from opentrons.hardware_control import SyncHardwareAPI
11+
from opentrons.hardware_control import (
12+
HardwareControlAPI,
13+
ThreadManager,
14+
SynchronousAdapter,
15+
)
1216
from opentrons.hardware_control.modules.types import (
1317
ModuleModel as LegacyModuleModel,
1418
TemperatureModuleModel as LegacyTemperatureModuleModel,
@@ -94,19 +98,18 @@ class LegacyContextCreator:
9498

9599
def __init__(
96100
self,
97-
sync_hardware_api: SyncHardwareAPI,
101+
hardware_api: HardwareControlAPI,
98102
labware_offset_provider: LegacyLabwareOffsetProvider,
99103
) -> None:
100104
"""Prepare the LegacyContextCreator.
101105
102106
Args:
103-
sync_hardware_api: The interface to the hardware API that the created
104-
Protocol API v2 contexts will use. Regardless of
105-
``use_simulating_implementation``, this can either be a real hardware
106-
API to actually control the robot, or a simulating hardware API.
107+
hardware_api: The hardware control interface.
108+
Will be wrapped in a `SynchronousAdapter`.
109+
May be real hardware or a simluator.
107110
labware_offset_provider: Interface for the context to load labware offsets.
108111
"""
109-
self._sync_hardware_api = sync_hardware_api
112+
self._hardware_api = hardware_api
110113
self._labware_offset_provider = labware_offset_provider
111114

112115
def create(self, protocol: LegacyProtocol) -> LegacyProtocolContext:
@@ -118,11 +121,16 @@ def create(self, protocol: LegacyProtocol) -> LegacyProtocolContext:
118121
else None
119122
)
120123

124+
if isinstance(self._hardware_api, ThreadManager):
125+
sync_hardware = self._hardware_api.sync
126+
else:
127+
sync_hardware = SynchronousAdapter(self._hardware_api)
128+
121129
return LegacyProtocolContext(
122130
api_version=api_version,
123131
labware_offset_provider=self._labware_offset_provider,
124132
implementation=self._ContextImplementation(
125-
sync_hardware=self._sync_hardware_api,
133+
sync_hardware=sync_hardware,
126134
api_version=api_version,
127135
extra_labware=extra_labware,
128136
),

api/src/opentrons/protocol_runner/protocol_runner.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Protocol run control and management."""
2-
from typing import List, NamedTuple, Optional, cast
2+
from typing import List, NamedTuple, Optional
33

4-
from opentrons.hardware_control import HardwareControlAPI, ThreadManagedHardware
4+
from opentrons.hardware_control import HardwareControlAPI
55
from opentrons.protocol_reader import (
66
ProtocolSource,
77
PythonProtocolConfig,
@@ -73,9 +73,7 @@ def __init__(
7373
self._python_executor = python_executor or PythonExecutor()
7474
self._legacy_file_reader = legacy_file_reader or LegacyFileReader()
7575
self._legacy_context_creator = legacy_context_creator or LegacyContextCreator(
76-
# TODO(mc, 2022-02-05): handle this cast more gracefully, probably in
77-
# a more specific runner implementation as mentioned in TODO below
78-
sync_hardware_api=cast(ThreadManagedHardware, hardware_api).sync,
76+
hardware_api=hardware_api,
7977
labware_offset_provider=LegacyLabwareOffsetProvider(
8078
labware_view=protocol_engine.state_view.labware,
8179
),

robot-server/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,13 @@ def session_manager(hardware: HardwareControlAPI) -> SessionManager:
264264

265265

266266
@pytest.fixture
267-
def set_enable_http_protocol_sessions(
267+
def set_disable_fast_analysis(
268268
request_session: requests.Session,
269269
) -> Iterator[None]:
270270
"""For integration tests that need to set then clear the
271271
enableHttpProtocolSessions feature flag"""
272272
url = "http://localhost:31950/settings"
273-
data = {"id": "enableHttpProtocolSessions", "value": True}
273+
data = {"id": "disableFastProtocolUpload", "value": True}
274274
request_session.post(url, json=data)
275275
yield None
276276
data["value"] = None

robot-server/tests/integration/http_api/protocols/test_upload.tavern.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,47 @@ stages:
6565
errors:
6666
- id: ProtocolNotFound
6767
title: Protocol Not Found
68+
69+
---
70+
test_name: Upload, analyze and analyze using "slow analysis"
71+
72+
marks:
73+
- usefixtures:
74+
- run_server
75+
- set_disable_fast_analysis
76+
77+
stages:
78+
- name: Upload simple Python protocol
79+
request:
80+
url: '{host:s}:{port:d}/protocols'
81+
method: POST
82+
files:
83+
files: 'tests/integration/protocols/simple.py'
84+
response:
85+
save:
86+
json:
87+
protocol_id: data.id
88+
analysis_id: data.analysisSummaries[0].id
89+
status_code: 201
90+
91+
- name: Retry until analyses status is completed and result is ok.
92+
max_retries: 10
93+
delay_after: 0.1
94+
request:
95+
url: '{host:s}:{port:d}/protocols/{protocol_id}/analyses'
96+
method: GET
97+
response:
98+
strict:
99+
- json:off
100+
status_code: 200
101+
json:
102+
data:
103+
- id: '{analysis_id}'
104+
status: completed
105+
result: ok
106+
- name: Delete the protocol
107+
request:
108+
url: '{host:s}:{port:d}/protocols/{protocol_id}'
109+
method: DELETE
110+
response:
111+
status_code: 200

0 commit comments

Comments
 (0)