Repository navigation
tests: deterministic virtual-clock stream conformance - #118
Merged
Merged
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 22 minutes. View limit details
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. |
Long stream timelines now run in virtual time, so a five-minute SSE, a
60-second idle body, the 30-second waitUntil budget and a stalled
TransformStream producer cost milliseconds of CI instead of minutes,
reproducibly.
- One clock: `asyncrt::mono_now` returns `tokio::time::Instant::now()`, and
the domain's start instant (stamped inside its own runtime) plus
`InFlight::{started, background_since}` and the event-start stamps read
it. Every other wait in the runtime is already a Tokio timer, so a test
that pauses the clock moves every deadline together. Unpaused, it reads
the same monotonic clock `std` does: no production change.
- `crates/cello/tests/virtual_clock_conformance.rs` drives the real
`runtime::drive` against a real Worker on a `start_paused` current-thread
runtime and reads the response body the way the shell does:
* a two-minute-plus SSE survives five virtual minutes with all 30 events
(fails on the pre-#103 waitUntil registration: the body is cut after the
30 s budget);
* a silent body ends at its 60 s idle deadline and not one second earlier
(fails without the clock seam: the sweeper re-arms forever);
* answered `waitUntil` work is cut at the background budget, not before
it and not at the 300 s handler budget;
* a `TransformStream` producer parks while its consumer does not read and
resumes when it does (#105);
* a proptest over seeded chunk schedules and drain orders: a tee of a tee
delivers byte-identical data on every branch (#111), with the failing
seed and minimal input printed, plus a fixed test for the one recorded
schedule because seeds are random.
Each scenario asserts its own wall time stays under a second, and every
driven request is awaited to retire instead of detached so one scenario's
isolate cannot leak into the next.
- Dev-only `tokio` `test-util` enables the paused clock; `proptest` (already
a workspace dependency) is now used. Failures persist beside the crate.
- CONTRIBUTING "Testing locally" documents the pattern, the deadlines that
must read the seam, and the ones deliberately left on `std`.
ryuzdev
force-pushed
the
tests/virtual-clock
branch
from
November 22, 2026 09:46
cb3219e to
7d9f711
Compare
This was referenced Nov 22, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Stream timing bugs are found by dogfood, not tests: a 5-minute SSE or a 60-second idle body is not affordable in CI. This runs the real request driver in-process on a paused Tokio clock, so long timelines take milliseconds and are reproducible.
asyncrt::mono_now()is now the single monotonic source (tokio::time::Instant::now()), and the domain's start instant (stamped inside its own runtime) plusInFlight::{started, background_since}and the event-start stamps read it. Every other wait in the runtime is already a Tokio timer (runtime.rswake loop,http_streamssweeper viaDomainToken::sleep_until, JSsetTimeout). A paused clock therefore moves every deadline together. Unpaused,tokio::time::Instantreads the same monotonic clockstddoes — no production behaviour change.crates/cello/tests/virtual_clock_conformance.rs: astart_pausedcurrent-thread runtime, apool::Poolisolate,runtime::drive, and the response body read as the shell reads it.waitUntilwork is cut at the 30 s background budget, not before it and not at the 300 s handler budget.TransformStreamproducer parks while the consumer does not read, then resumes (runtime: TransformStream applies backpressure #105).retire) instead of detached, so no isolate leaks into the next scenario.tokiotest-utilenables the paused clock;proptest(already a workspace dep, unused) is now used. Failure seeds persist undercrates/cello/proptest-regressions/.std(SQL statement deadline, egress DNS TTL,main.rswindows, CPU watchdog).Fail-before (each reverted, observed, restored)
op_response_stream_hold→register_wait_until(pre-1b498a8) → SSE test fails: "ended after 2 events, HTTP stream 1 expired after 60 seconds of inactivity, 80s into a five-minute stream".writable_stream.jstransformwritewithout the backpressure wait (pre-b8b9993) → "the producer wrote the whole body before the consumer read a chunk … (the pre-runtime: TransformStream applies backpressure #105 behaviour)".git stashof the asyncrt/js seam (stdInstant) → "the idle deadline ends the body: Elapsed(())".background_expiredgate inruntime.rs::wake_with_cross_entry_gatedisabled → "the background budget ends the leftover work: Elapsed(())".cc 03674d89…, minimal inputsizes = [1025], order = "lockstep".Verification
cargo test --profile ci --locked -p cello --test virtual_clock_conformance→ 6 passed, 0.17 s total.--test-threads=4→ 30/30 green; 10× with--test-threads=1→ 10/10 green.cargo test --profile ci --locked -p cello --lib→ 573 passed, 0 failed.cargo clippy --profile ci --locked -p cello --lib --bins --tests -- -D warningsclean;cargo fmt --all --checkclean.