Repository navigation
tests: the MQTT retry SIL's fake clock applies only to the test thread - #151
Merged
Merged
Conversation
Base station protocol tests failed once on #150 (220ea72, push run): test_MR_C_raises_after_30s_monotonic_deadline recorded 13355 sleeps against a limit of 10. The same commit passed in its pull_request run. Each web_ui import starts a radio-auto daemon (#91) that loops on time.sleep(5.0), and the suite reloads web_ui about 40 times. The SIL patches sleep and monotonic on the time module, which every thread shares, so a worker that woke inside a patched window called the fake sleep, which returns at once, and spun until the patch ended, filling clock.sleeps. Forcing a worker to wake inside MR-C's window reproduced it (49366 sleeps). The fake clock now applies only to the thread that made it. Other threads get the real sleep and monotonic. The same forced wake records the 9 expected sleeps. New MR-E test: another thread sleeping while the clock is patched leaves clock.sleeps empty and reads real time. It fails on the old clock with [0.01, 0.01, 0.01]. base_station: 1616 passed, 2 skipped. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017xHffg93jSdYuYEWpSUWeR
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused test-only fix addresses shared-clock interference without identified blocking issues.
0 open findings
What changed in this PR
This test-only change prevents background threads from interfering with the MQTT retry tests’ fake clock. Production code is unchanged.
Changes:
- Restricts fake time to the thread that created the clock.
- Adds MR-E regression coverage confirming other threads use real time without modifying fake-clock state.
| File | Description |
|---|---|
| LifeTrac-v25/DESIGN-CONTROLLER/base_station/tests/test_mqtt_retry_backoff_sil.py | Isolates the fake clock by thread and adds regression coverage. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Requested by Dorkmo · project thread
Before:
Base station protocol testscould fail at random intest_MR_C_raises_after_30s_monotonic_deadline. It failed once on #150: 13,355 sleeps recorded against a limit of 10, on a commit whose other run passed.After: the MQTT retry SIL's fake clock only changes time for the test thread, so that failure cannot recur.
Each
web_uiimport starts aradio-autodaemon thread (from #91) that loops ontime.sleep(5.0). The suite reloadsweb_uiabout 40 times.test_mqtt_retry_backoff_sil.pypatchessleepandmonotonicon thetimemodule, which every thread shares. A worker that woke while a patch was active called the fake sleep, which returns at once, so it spun and filledclock.sleepsuntil the patch ended.How
_FakeClockrecords the thread that created it. Calls from any other thread go to the realtime.sleepandtime.monotonic, captured when the module loads.The new test
MR-Estarts a thread that sleeps while the clock is patched. It checks thatclock.sleepsstays empty and that the thread reads real time.Test-only change. No production code changes.
How it was checked
radio-autoworker to wake inside MR-C's patched window recorded 49,366 sleeps with the old clock. With the fix it recorded the expected 9 (0.5, 1, 2, 4, then 5 five times).MR-Efails on the old clock with[0.01, 0.01, 0.01] != [], and passes with the fix.base_station:python -m pytest tests -qgives 1616 passed, 2 skipped.🤖 Generated with Claude Code
https://claude.ai/code/session_017xHffg93jSdYuYEWpSUWeR
Generated by Claude Code