Skip to content

ev: fix flaky realtime timer test (measure in its own clock domain) - #635

Merged
lalinsky merged 1 commit into
mainfrom
fix-real-timer-flake
Aug 1, 2026
Merged

lalinsky merged 1 commit into
mainfrom
fix-real-timer-flake

Conversation

@lalinsky

@lalinsky lalinsky commented Aug 1, 2026

Copy link
Copy Markdown
Owner

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_ABSOLUTE on Darwin, TFD_TIMER_ABSTIME on Linux) — so a wall-clock step during the 100ms window moves the firing moment in monotonic terms: a forward step trips the >= 90ms bound, a backward step (plus load) the <= 250ms one.

That's why it flaked specifically on macOS CI: the macOS runner VMs drift and timed corrects 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.

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.
@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e466854c-a048-4116-8051-55f38532a551

📥 Commits

Reviewing files that changed from the base of the PR and between b22ffc6 and 1b342dd.

📒 Files selected for processing (1)
  • src/ev/test/timer.zig

📝 Walkthrough

Walkthrough

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

Changes

Realtime timer test

Layer / File(s) Summary
Realtime timestamp measurement
src/ev/test/timer.zig
The test captures the initial realtime timestamp, derives the deadline from it, and computes elapsed duration from a second realtime timestamp. Comments document wall-clock step handling.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

Start time captured, the deadline is clear,
Realtime ticks now steer the test gear.
The stopwatch steps aside,
Wall-clock shifts cannot hide.
Two timestamps mark the timer’s flight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the fix for the flaky realtime timer test.
Description check ✅ Passed The description directly explains the timer test failure and the realtime-clock measurement fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-real-timer-flake

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lalinsky
lalinsky merged commit 6629bda into main Aug 1, 2026
29 checks passed
@lalinsky
lalinsky deleted the fix-real-timer-flake branch August 1, 2026 05:20
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.

1 participant