Skip to content
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

chore(api): further speed up ot3controller tests and add profiling #12132

Merged
merged 4 commits into from
Feb 10, 2023

Conversation

sfoster1
Copy link
Member

@sfoster1 sfoster1 commented Feb 10, 2023

Some of our tests are really slow and it's a pain to figure out why! This PR

pytest-profiling is a pytest module that will automatically profile your tests for you if you
so wish. If you add --profile to your test command, it will dump out
top-ten calls by time, and it will dump more in-depth profiling data to
prof/ which can be interpreted with the python stdlib pstats/ module.

Also, add some fixes based on findings from profiling:

OT3 gpio sleep

The OT3 gpio drivers have a sleep(1) in their init method. This isn't
great, and will soon be removed - it was required for some nasty
interactions between estop initialization and our canbus driver when it
was initializing, and on later revs we don't need to handle the estop
line like this - but in the meantime we can patch it out.

This makes these tests take about a second in total instead of 80 seconds.

threadmanager cleanup

In the cleanup of the thread manager, we were doing an
asyncio.sleep(0.1) to spin the loop to make sure some classes cleaned
up. Since then, we've learned that a 0-second sleep does the same thing.
Changing the 0.1 to 0 should not present any changes in behavior (and if
it does, they're in a cleanup method that is basically never run in
prod) and doubles the speed of the tests in hardware_control. it makes those
tests take 9s instead of 25s.

Risk

None, tests only (and no test behavior changes, either)

pytest-profiling ( https://pypi.org/project/pytest-profiling/ ) is a
pytest module that will automatically profile your tests for you if you
so wish. If you add --profile to your test command, it will dump out
top-ten calls by time, and it will dump more in-depth profiling data to
`prof/` which can be interpreted with the python stdlib pstats/ module.
The OT3 gpio drivers have a sleep(1) in their init method. This isn't
great, and will soon be removed - it was required for some nasty
interactions between estop initialization and our canbus driver when it
was initializing, and on later revs we don't need to handle the estop
line like this - but in the meantime we can patch it out.

This makes these tests take about a second in total instead of 80 seconds.
@sfoster1 sfoster1 requested a review from a team as a code owner February 10, 2023 19:23
@codecov
Copy link

codecov bot commented Feb 10, 2023

Codecov Report

Merging #12132 (637116d) into edge (dc285e5) will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             edge   #12132      +/-   ##
==========================================
- Coverage   74.29%   74.29%   -0.01%     
==========================================
  Files        2159     2159              
  Lines       59555    59554       -1     
  Branches     6093     6093              
==========================================
- Hits        44248    44247       -1     
  Misses      13945    13945              
  Partials     1362     1362              
Flag Coverage Δ
notify-server 89.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...i/src/opentrons/hardware_control/thread_manager.py 88.37% <ø> (-0.09%) ⬇️

Copy link
Contributor

@fsinapi fsinapi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@Laura-Danielle Laura-Danielle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow

In the cleanup of the thread manager, we were doing an
asyncio.sleep(0.1) to spin the loop to make sure some classes cleaned
up. Since then, we've learned that a 0-second sleep does the same thing.
Changing the 0.1 to 0 should not present any changes in behavior (and if
it does, they're in a cleanup method that is basically never run in
prod) and doubles the speed of the tests in hardware_control.
We start and stop a lot of module servers, and polling to see whether
they're started should be a lot faster now.
@sfoster1 sfoster1 merged commit 86e6e16 into edge Feb 10, 2023
@sfoster1 sfoster1 deleted the speed-up-tests branch February 10, 2023 19:59
y3rsh added a commit that referenced this pull request Feb 13, 2023
* origin/edge: (31 commits)
  refactor(hardware): Update appropriate revision (#12130)
  fix(api): Fix accidental error on any PAPIv2.14 protocol (#12141)
  refactor(api): Allow homing after drop tip in engine core (#12124)
  fix(shared-data): remove newLocation and strategy from schemav6 (#12133)
  refactor(api): load pipette with useVirtualPipettes config option (#12117)
  chore(api): further speed up ot3controller tests and add profiling (#12132)
  docs(api): Settle in to leave Labware.default_magdeck_engage_height alone, for now (#12122)
  refactor(api): Improve error messages for JSONv6 and PAPIv2.14 protocols (#12131)
  refactor(robot-server): Note mistaken type in migration (#12126)
  chore(hardware): Remove docstring content checks (#12128)
  feat(hardware_control): Added firmware update mechanism for submodules (#12076)
  feat(app): remove feature flag for calibration dashboard and wizard updates (#12125)
  feat(app):  Calibration dashboard wizard data invalidation (#12097)
  feat(hardware): support new revision values (#12111)
  feat(app): add Chip component (#12090)
  docs(api): Officially remove the `height` parameter of `MagneticModuleContext.engage()` (#12114)
  feat(system-server): add persistent UUID generation (#12123)
  feat(odd): add manual connection for a hidden network (#12033)
  feat(hardware): add progress output to subsystem firmware update process (#12059)
  refactor(api): Improve OT3 instrument calibration process (#11807)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants