-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): refactor protocol api integration tests to prevent thread l…
…eakage (#16834) Fixes an issue found where after a recent mergeback commit into edge, API unit tests were hanging and failing due to thread leakage in protocol api integration tests.
- Loading branch information
Showing
5 changed files
with
211 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Fixtures for protocol api integration tests.""" | ||
|
||
import pytest | ||
from _pytest.fixtures import SubRequest | ||
from typing import Generator | ||
|
||
from opentrons import simulate, protocol_api | ||
from opentrons.protocol_api.core.engine import ENGINE_CORE_API_VERSION | ||
|
||
|
||
@pytest.fixture | ||
def simulated_protocol_context( | ||
request: SubRequest, | ||
) -> Generator[protocol_api.ProtocolContext, None, None]: | ||
"""Return a protocol context with requested version and robot.""" | ||
version, robot_type = request.param | ||
context = simulate.get_protocol_api(version=version, robot_type=robot_type) | ||
try: | ||
yield context | ||
finally: | ||
if context.api_version >= ENGINE_CORE_API_VERSION: | ||
# TODO(jbl, 2024-11-14) this is a hack of a hack to close the hardware and the PE thread when a test is | ||
# complete. At some point this should be replaced with a more holistic way of safely cleaning up these | ||
# threads so they don't leak and cause tests to fail when `get_protocol_api` is called too many times. | ||
simulate._LIVE_PROTOCOL_ENGINE_CONTEXTS.close() | ||
else: | ||
# If this is a non-PE context we need to clean up the hardware thread manually | ||
context._hw_manager.hardware.clean_up() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.