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
Fix tests that leak threads (pytest 8) #3358
Conversation
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.
Thanks for this work! My main worry is the reliability of the time-based logic. You would expect LONG_TIMEOUT * 3
to be enough, but CI always surprises me in this regard. We'll have to be ready to bump that constant if needed. Thankfully bumping it will not make the happy path slower.
I've increased it to
|
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've removed the print statements, extraneous, comments, and the unnecessary time.sleep()
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, thanks for this!
Thanks for this work! My main worry is the reliability of the time-based logic. You would expect
LONG_TIMEOUT * 3
to be enough, but CI always surprises me in this regard. We'll have to be ready to bump that constant if needed. =I've increased it to
LONG_TIMEOUT *2 + 5.0
, in principle the maximum time that the thread can take to notice thequit_event
isLONG_TIMEOUT
and the thread should terminate immediately (0.1s) after that. If it takes more than 5 seconds something must be wrong.
What do you think about adding a comment to the code describing why LONG_TIMEOUT * 2 + 5.0
was chosen?
- introduces a new pytest marker
server_threads
to allow to test funcionality. I can remove this marker after but right now you can test this withnox -rs test-3.10 -- -m server_threads
I'd drop server_threads
before the PR is merged if there is no expected use for the marker.
Done, in latest version
Done |
Co-authored-by: Illia Volochii <illia.volochii@gmail.com>
Co-authored-by: Illia Volochii <illia.volochii@gmail.com>
I'll merge this to include the changes in a base for a #3366 fix |
Bumping the pytest version to 8.0.2 revealed that some tests are leaking threads. The tests create a SocketServerThread and those threads never finish. These unterminated threads confuse pytest-memray since while running a test one of these threads can do an allocation that will be counted as part of this test.
In particular the following tests currently do not properly terminate the threads:
pytest.skip()
)pytest.skip()
)pytest.skip()
)This PR addresses the problem by
quit_event
, on theteardown_method
we signal the quit_event and the socket_handlers can read it, and acts appropriately.server_threads
to allow to test funcionality. I can remove this marker after but right now you can test this withnox -rs test-3.10 -- -m server_threads
Closes #3335
Alternatives
@pytest.mark.limit_memory("10.10 MB")
. This does not fix the problem but it's way easier and less convoluted. But ideally we should not leave threads lingering from test to test.test_socket_close_socket_then_file
I believe they really need a outside signal* test_chunked_specified[bytes-POST-False]
, should not even create a server thread in the first place, the whole test can be SKIPPED beforeself._start_server(socket_handler)
.