Skip to content

kj-rs-tokio: Test that a zero timeout doesn't park, not how long it takes - #8568

Merged
nathanwhit merged 1 commit into
mainfrom
nathanwhit/kj-rs-tokio-due-timer-parks
Nov 18, 2026
Merged

nathanwhit merged 1 commit into
mainfrom
nathanwhit/kj-rs-tokio-due-timer-parks

Conversation

@nathanwhit

@nathanwhit nathanwhit commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

an already-due timer fires without waiting for a tokio tick (added in #8476) required the median of nine zero-delay timer waits to be under 1 ms. A due timer doesn't sleep, but the wait still costs a TokioPort::poll(), whose 16 yields to tokio take about 0.4 ms on an M5 Pro and about 1.3 ms on CI's macOS runners: more than the 1 ms tick the test means to rule out. Every run on CI's macOS runners fails it once something forces the test to re-run (e.g. #8248), and with every core busy it fails 5 to 8 runs in 30 locally on main.

This replaces it with a Rust unit test of the fix it guarded, wait_timeout_ns(0) polling instead of parking. A task spawned before the call runs during it either way, and records whether the port was parked (SharedState::in_wait). The test fails if the zero-timeout check is removed. The C++ side needs no test of its own: TokioEventPort::wait() passes on the zero timeout that kj::TimerImpl::timeoutToNextEvent() returns for a due timer.

Separately, the cost of poll() means a setTimeout(fn, 0) still takes about 0.4 ms locally and over 1 ms on CI's macOS runners; with POLL_YIELD_BUDGET at 1 it takes about 20 µs. That's not addressed here.

@nathanwhit
nathanwhit requested review from a team as code owners November 18, 2026 02:29

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Superseded by the review of 9ad476c8.

This review, of fede11a2

✅ Approved — This pull request replaces a flaky timing check with a park count that checks the behaviour directly. I found no issues in the code or the docs.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

The park counter is incremented once per block_on in wait_*, so it counts exactly what the tests mean to rule out. The C++ and Rust tests each check one half of the fix.


📝 Documentation: ✅ LGTM

The doc comments on park_count and on the new tests describe what the code does now.


Reviewed commit: fede11a2

…akes

"an already-due timer fires without waiting for a tokio tick" required
the median of nine zero-delay timer waits to be under 1 ms. A due timer
doesn't sleep, but the wait still costs a TokioPort::poll(), whose 16
yields to tokio take about 0.4 ms on an M5 Pro and about 1.3 ms on CI's
macOS runners: more than the 1 ms tick the test means to rule out. Every
run on CI's macOS runners failed it, and with every core busy it failed
5 to 8 runs in 30 locally.

Replace it with a Rust unit test of the fix it guarded,
wait_timeout_ns(0) polling instead of parking: a task spawned before the
call runs during it either way, and records whether the port was parked
(SharedState::in_wait). It fails if the zero-timeout check is removed.
The C++ side needs no test of its own: TokioEventPort::wait() passes on
the zero timeout that kj::TimerImpl::timeoutToNextEvent() returns for a
due timer.
@nathanwhit
nathanwhit force-pushed the nathanwhit/kj-rs-tokio-due-timer-parks branch from fede11a to 9ad476c Compare November 18, 2026 02:35
@nathanwhit nathanwhit changed the title kj-rs-tokio: Test that a due timer doesn't park, not how long it takes kj-rs-tokio: Test that a zero timeout doesn't park, not how long it takes Nov 18, 2026
@nathanwhit
nathanwhit enabled auto-merge November 18, 2026 02:36

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Approved — The new test checks the zero-timeout behaviour directly instead of timing it, and the flaky timing test is removed. No issues found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

The test reads in_wait from a task that runs inside the call, so it tells polling apart from parking without depending on timing. It fails if the zero-timeout early return in wait_timeout_ns is removed.


📝 Documentation: ✅ LGTM

The doc comment on zero_timeout_does_not_park describes the current behaviour and why it matters (tokio's 1 ms tick rounding).


Reviewed commit: 9ad476c8

@nathanwhit
nathanwhit merged commit 8047c1c into main Nov 18, 2026
24 checks passed
@nathanwhit
nathanwhit deleted the nathanwhit/kj-rs-tokio-due-timer-parks branch November 18, 2026 02:56
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.

2 participants