fix: widen thread-leak fixture grace period to match stop()'s timeout - #82
Merged
Conversation
…imeout ElectronicControlUnit.stop() joins the dispatch thread with a default dispatch_join_timeout of 3.0s, and only logs a warning (rather than failing) if the thread is still alive after that — tolerating slow subscriber callbacks by design. The autouse _assert_no_j1939_thread_leak fixture in conftest.py was only polling for 200ms, well under stop()'s own tolerance, which could produce false-positive leak failures for any test exercising a slow-callback shutdown path under scheduling load. Widen the fixture's poll window to 3.5s so it never gives up sooner than stop() itself considers acceptable, without weakening the check for tests that genuinely leak (the loop still exits early once the leaked threads disappear). Fixes #81 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
drewr95
approved these changes
Aug 28, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
test/conftest.py's autouse_assert_no_j1939_thread_leakfixture only polled for 200ms after each test for leakedj1939.*background threads to disappear.ElectronicControlUnit.stop()(j1939/electronic_control_unit.py:158) joins the dispatch thread with a defaultdispatch_join_timeoutof 3.0s and only logs a warning — rather than failing — if the thread is still alive after that, by design (to tolerate a slow subscriber callback unwinding).Because the fixture's window (200ms) was much shorter than
stop()'s own tolerance (3.0s), any test exercising a slow-callback shutdown path could intermittently fail with a false-positive "leaked thread" assertion under scheduling load — even though nothing was actually leaked, the thread just hadn't finished exiting within the fixture's much stricter window.Fix
Widen the fixture's poll window to 3.5s (slightly above
stop()'s own 3.0s default), so the fixture never gives up sooner thanstop()itself considers acceptable. The loop still exits early as soon as leaked threads disappear, so this doesn't slow down the common case — only tests that are already close to the edge ofstop()'s timeout benefit from the wider window.Fixes #81
Related
Companion to #80, which fixed one instance of this flake in
test_dispatch_queue_drop_on_fullby having that specific test explicitly join its ECU's threads instead of relying on the fixture. This PR addresses the general case for any other current or future slow-callback test.Test plan
pytest test/test_threading.py -q— 23 passedpytest . --pyargs -q— 527 passedruff check test/conftest.py— clean