Skip to content

Commit cf2341f

Browse files
authored
chore: Merge pull request #82 from RaulSMS/fix/81-thread-leak-fixture-timeout
fix: widen thread-leak fixture grace period to match stop()'s timeout
2 parents f0fba17 + 551ad64 commit cf2341f

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

test/conftest.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,28 @@ def feeder():
2121

2222
@pytest.fixture(autouse=True)
2323
def _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, (

0 commit comments

Comments
 (0)