fix(api): refactor protocol api integration tests to prevent thread leakage #16834
+211
−118
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This fixes an issue found where after a recent mergeback commit into edge, API unit tests were hanging and when escaped, would show as a bunch of
OSError: [Errno 24] Too many open files
.Through investigation this was found to be caused by too many integration tests that individually called
simulate.get_protocol_api
. There is a known issue with this in that the threads this creates (Hardware API and for 2.14 and above contexts, Protocol Engine) are not cleaned up properly. This was not causing any issues in our test suite until recently when the magic number of tests that could be run without too many threads opening was hit.In order to fix this, the simulating context was refactored to be a pytest fixture. In this new fixture, we yield a
ProtocolContext
and then afterwards, we close the threads. For engine based contexts, we take advantage of the glboalExitStack()
simulate
uses to create the PE context to close and unwind the context stack they are created in, allowing it to be properly garbage collected. For older contexts we just call theclean_up
function on the hardware API instance.Test Plan and Hands on Testing
This is a test only fix, so if CI passes this covers this PR.
Changelog
protocol_api_integration
tests to prevent thread leakageReview requests
Can someone else who has this failing test this on their machine to ensure this fix works for not just me.
Risk assessment
Low.