-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(api): Configure ctx fixture as PAPIv2.14 when it's configured as an OT-3 #12567
Conversation
Codecov Report
@@ Coverage Diff @@
## edge #12567 +/- ##
=======================================
Coverage 73.31% 73.31%
=======================================
Files 1506 1506
Lines 49349 49349
Branches 2997 2997
=======================================
Hits 36180 36180
Misses 12713 12713
Partials 456 456
Flags with carried forward coverage won't be shown. Click here to find out more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do agree with all of this. I think making a protocol context with an ot3 does make sense in practice, since people have been using it since before the contents of 2.14 existed, but I think it shouldn't.
I do in fact think that it's a good idea to test OT-2 + 2.14, but I think we've got a neat path set out for that and do not have to do it in this PR; I think PRs that move things forward but perhaps not far enough are good to merge and be taken up later.
Couple inline things though.
I think this is because we never start a task from inside this worker thread. Tasks are always given to the worker thread from outside of it.
15c4918
to
8da6f39
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this makes more sense, and I think you've got the right set of things to test. In terms of loop cleanup... this is entirely a test artifice, and I think you're exactly right that we hsouldn't worry about it too much.
4f5ea2c
to
11d8434
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this looks fine. I'd kinda prefer having the functionality in threadmanager but if this works it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, this is definitely needed to make our tests more accurate and I think this is the right step forward.
Totally. It's important, but can be achieved in a follow-up. |
Overview
The
api
tests have this top-levelctx
pytest fixture:opentrons/api/tests/opentrons/conftest.py
Lines 258 to 260 in a89d965
Right now, any tests that use this
ctx
fixture will try to run under two configurations:version="2.13"
With this PR, that changes to this:
version="2.13"
version="2.14"
This work is one part of RLAB-250, and it will also help with RCORE-535.
Test plan
api
tests keep passing, both locally and in CI.api
tests don't have any hangs.api
tests don't have any new flaky failures.Why
PAPIv2.14 runs through Protocol Engine, and PAPIv2.13 runs through the legacy PAPI back-end.
The legacy PAPI back-end will not support the OT-3. So this fixture was "wrong," in the sense that it was causing tests to run in a configuration that we don't expect to work.
In practice, it's happened to work so far. At least, it's worked well enough. However, in my work on RLAB-250, it stopped working well enough. I wanted to change the OT-3's deck definition to have slot names like
"D1"
instead of"1"
, but PAPIv2.13'sDeck
class isn't built to support that, so I got a bunch of errors from the PAPIv2.13Deck
class:How
This turns out to be tricky because of concurrency stuff.
When
ProtocolEngine
is used to execute a Python protocol, the two must be in separate threads. This is becauseProtocolEngine
expects to be in anasyncio
event loop, whereas the Python Protocol API is all blocking and non-async
. If we tried to put them in the same thread, they would deadlock.PipetteContext.aspirate()
would enqueue a Protocol Engineaspirate
command and wait for it to complete, but it would never complete because theProtocolEngine
's background command execution task would never have a chance to run, because the thread is blocked onpipette.aspirate(...)
and not yielding to theasyncio
event loop!In
robot-server
's production code, we solve this by keeping theProtocolEngine
in the "main thread"'s event loop and stuffing the Python protocol in a "worker thread." Here, inapi
's tests, we need to do the reverse. The "main thread" is already occupied by the pytest tests, so we need to stuff theProtocolEngine
into a worker thread.This means the
ctx
fixture needs to:asyncio
event loop.asyncio
event loop, start running aProtocolEngine
.This is one of the problems that
ThreadManager
solves for the hardware API. We're basically inventing a newThreadManager
forProtocolEngine
.We do get to avoid some of
ThreadManager
's pitfalls, though.ThreadManager
does two things: keep an async object in a background thread, and facilitate safe access to that async object. In our case, facilitation of safe access is already done bySyncClient
, so we only need to solve the problem of keeping the async object in the background thread.Review requests
Reinventing parts of
ThreadManager
forProtocolEngine
isn't something that we should take lightly. We should question several premises of this PR.ProtocolContext
as an OT-3—that is, with an OT-3 hardware controller and an OT-3 deck definition—is fundamentally wrong, right?opentrons.execute.get_protocol_api(version="2.14")
for RCORE-535. Do you agree?Plus some finer points:
Should we be trying to deduplicate things more with
ThreadManager
instead of writing this background thread machinery from scratch? On one hand, duplication is bad, but on the other,ThreadManager
is unnecessarily complicated for this purpose.Do we also want to test the combination of OT-2 and PAPIv2.14? In other words, do we want this?
version="2.13"
version="2.14"
Risk assessment
So far, changes are just to tests, so there's no risk to breaking production behavior.
There is some risk of introducing architectural debt. See the review requests above.