File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,18 +21,28 @@ def feeder():
2121
2222@pytest .fixture (autouse = True )
2323def _assert_no_j1939_thread_leak ():
24- """Fail any test that leaves a j1939.* background thread alive."""
24+ """Fail any test that leaves a j1939.* background thread alive.
25+
26+ The poll window here (3.5s) is deliberately kept slightly above
27+ ElectronicControlUnit.stop()'s own default dispatch_join_timeout (3.0s):
28+ stop() only logs a warning (rather than failing) if the dispatch thread
29+ doesn't exit within that timeout, e.g. while a slow subscriber callback
30+ unwinds. If this fixture's window were shorter than stop()'s own
31+ tolerance, a thread that stop() itself considers "still fine, just slow"
32+ could trip a false-positive leak failure here. See #81.
33+ """
2534 before = {t .ident for t in threading .enumerate ()
2635 if t .name .startswith ('j1939.' )}
2736 yield
28- # Give freshly-stopped threads a brief moment to actually exit.
37+ # Give freshly-stopped threads a chance to actually exit.
2938 import time
30- for _ in range (20 ):
39+ deadline = time .monotonic () + 3.5
40+ while True :
3141 leaked = [t for t in threading .enumerate ()
3242 if t .name .startswith ('j1939.' )
3343 and t .ident not in before
3444 and t .is_alive ()]
35- if not leaked :
45+ if not leaked or time . monotonic () >= deadline :
3646 break
3747 time .sleep (0.01 )
3848 assert not leaked , (
You can’t perform that action at this time.
0 commit comments