test: eliminate flaky time.sleep() tests with deterministic coordination#115
Conversation
Replaces 26 flaky time.sleep() calls across 5 test files with
deterministic synchronization primitives:
- ThreadGate: named sync points for thread coordination (new helper)
- TimingHelper.wait_for_condition: poll observable state instead of
hoping sleep durations are sufficient
- collector.flush(): use existing drain API instead of sleeping
- time-machine: replace patch("time.time") for thread-safe clock
control (test_l1_swr.py)
Fixes the test_version_mismatch_aborts_refresh_concurrent flake that
blocks the release-please PR (#112).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThis PR reduces test timing flakiness by replacing sleep-based delays with deterministic synchronization. A new ChangesTest Timing Determinism
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
ThreadGatehelper totests/utils/timing_helper.py— named synchronization points for deterministic thread coordinationtime.sleep()calls across 5 test files with deterministic primitivestest_version_mismatch_aborts_refresh_concurrentflake blocking release-please PR chore(main): release 0.6.1 #112Changes by file
tests/unit/test_l1_swr.pypatch("time.time")+ sleep-based thread orderingtime-machine+threading.Eventtests/unit/test_load_control.pytime.sleep(0.05)"let thread acquire"ThreadGate+wait_for_conditiontests/critical/test_backpressure_load_control.pytime.sleep(0.05)"let it acquire"ThreadGate+wait_for_conditiontests/unit/test_metrics_collection.pytime.sleep(0.1)"allow time for processing"collector.flush()(existing API)tests/critical/conftest.pyWhat was NOT changed
time.sleepinside thread callbacks simulating real work (valid usage)Test plan
test_version_mismatch_aborts_refresh_concurrentpasses 50/50 in tight loopSummary by CodeRabbit