Repository navigation
ev: fix flaky realtime timer test (measure in its own clock domain) - #635
Conversation
The test armed an absolute realtime deadline but asserted the elapsed time on a monotonic stopwatch. A realtime timer fires when the wall clock crosses the deadline and is re-evaluated by the kernel across clock steps (NOTE_ABSOLUTE on Darwin, TFD_TIMER_ABSTIME elsewhere), so any step during the 100ms window shifts the firing moment in monotonic terms: a forward step fired it under the 90ms lower bound, a backward step pushed it past 250ms. macOS CI VMs step their wall clock frequently, which is why the flake showed up there; Linux runners usually slew instead. Measuring with now(.real) before and after keeps the assertion in the timer's own clock domain, where a step moves the current time and the deadline crossing together and the elapsed time stays ~100ms plus firing latency regardless.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe real-clock timer test now derives its deadline from an initial realtime timestamp and measures elapsed time with a second realtime timestamp. It no longer uses a monotonic stopwatch. ChangesRealtime timer test
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The
timer on real clock fires (absolute deadline)test arms an absolute deadline in the realtime epoch but asserted elapsed time on a monotonic stopwatch. A realtime timer fires when the wall clock crosses the deadline, and the kernel deliberately re-evaluates it across clock steps (NOTE_ABSOLUTEon Darwin,TFD_TIMER_ABSTIMEon Linux) — so a wall-clock step during the 100ms window moves the firing moment in monotonic terms: a forward step trips the>= 90msbound, a backward step (plus load) the<= 250msone.That's why it flaked specifically on macOS CI: the macOS runner VMs drift and
timedcorrects them by stepping, often several times early in a job, while Linux runners mostly slew. The timer behaves correctly in both cases; the test was measuring it with the wrong clock.Fix: measure elapsed with
now(.real)before and after. In the timer's own clock domain, a step moves the current time and the deadline crossing together, so elapsed stays ~100ms plus firing latency regardless of steps in either direction. The bounds keep their existing meaning (no early fire, bounded latency) without the false coupling to wall-clock corrections.