Skip to content

tests: the MQTT retry SIL's fake clock applies only to the test thread - #151

Merged
dorkmo merged 1 commit into
mainfrom
claude/project-thread-e2dnl1
Oct 14, 2026
Merged

dorkmo merged 1 commit into
mainfrom
claude/project-thread-e2dnl1

Conversation

@dorkmo

@dorkmo dorkmo commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Requested by Dorkmo · project thread

Before: Base station protocol tests could fail at random in test_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_ui import starts a radio-auto daemon thread (from #91) that loops on time.sleep(5.0). The suite reloads web_ui about 40 times. test_mqtt_retry_backoff_sil.py patches sleep and monotonic on the time module, 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 filled clock.sleeps until the patch ended.

How

_FakeClock records the thread that created it. Calls from any other thread go to the real time.sleep and time.monotonic, captured when the module loads.

The new test MR-E starts a thread that sleeps while the clock is patched. It checks that clock.sleeps stays empty and that the thread reads real time.

Test-only change. No production code changes.

How it was checked

  • Forcing a radio-auto worker 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-E fails on the old clock with [0.01, 0.01, 0.01] != [], and passes with the fix.
  • base_station: python -m pytest tests -q gives 1616 passed, 2 skipped.

🤖 Generated with Claude Code

https://claude.ai/code/session_017xHffg93jSdYuYEWpSUWeR


Generated by Claude Code

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

@dorkmo
dorkmo merged commit f6e4b46 into main Oct 14, 2026
23 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.

3 participants