Skip to content

fix: widen thread-leak fixture grace period to match stop()'s timeout - #82

Merged
drewr95 merged 1 commit into
masterfrom
fix/81-thread-leak-fixture-timeout
Aug 28, 2026
Merged

fix: widen thread-leak fixture grace period to match stop()'s timeout#82
drewr95 merged 1 commit into
masterfrom
fix/81-thread-leak-fixture-timeout

Conversation

@RaulSMS

@RaulSMS RaulSMS commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Summary

test/conftest.py's autouse _assert_no_j1939_thread_leak fixture only polled for 200ms after each test for leaked j1939.* background threads to disappear. ElectronicControlUnit.stop() (j1939/electronic_control_unit.py:158) 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, 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 than stop() 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 of stop()'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_full by 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 passed
  • pytest . --pyargs -q — 527 passed
  • ruff check test/conftest.py — clean
  • Confirmed wall-clock time for the full suite is unaffected (fixture still exits early on the happy path)

…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>
@RaulSMS
RaulSMS requested a review from khauersp August 28, 2026 09:43
@drewr95
drewr95 merged commit cf2341f into master Aug 28, 2026
17 checks passed
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.

Flaky test: test_dispatch_queue_drop_on_full occasionally fails the thread-leak fixture

2 participants