Skip to content

tests: deterministic virtual-clock stream conformance - #118

Merged
ryuzdev merged 1 commit into
mainfrom
tests/virtual-clock
Nov 22, 2026
Merged

ryuzdev merged 1 commit into
mainfrom
tests/virtual-clock

Conversation

@ryuzdev

@ryuzdev ryuzdev commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

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.

  • One clock seam. asyncrt::mono_now() is now the single monotonic source (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 (runtime.rs wake loop, http_streams sweeper via DomainToken::sleep_until, JS setTimeout). A paused clock therefore moves every deadline together. Unpaused, tokio::time::Instant reads the same monotonic clock std does — no production behaviour change.
  • crates/cello/tests/virtual_clock_conformance.rs: a start_paused current-thread runtime, a pool::Pool isolate, runtime::drive, and the response body read as the shell reads it.
  • Dev-only tokio test-util enables the paused clock; proptest (already a workspace dep, unused) is now used. Failure seeds persist under crates/cello/proptest-regressions/.
  • CONTRIBUTING documents the pattern, the deadlines that must read the seam, and the ones deliberately left on std (SQL statement deadline, egress DNS TTL, main.rs windows, CPU watchdog).

Fail-before (each reverted, observed, restored)

  1. runtime: stream response bodies past the background budget #103: 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".
  2. runtime: TransformStream applies backpressure #105: writable_stream.js transform write without 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)".
  3. Idle deadline: git stash of the asyncrt/js seam (std Instant) → "the idle deadline ends the body: Elapsed(())".
  4. Background budget: the background_expired gate in runtime.rs::wake_with_cross_entry_gate disabled → "the background budget ends the leftover work: Elapsed(())".
  5. Tee property: a reintroduced truncation in the JS tee pump (one branch loses its chunks over 1 KiB) → fails with seed cc 03674d89…, minimal input sizes = [1025], order = "lockstep".

Verification

  • cargo test --profile ci --locked -p cello --test virtual_clock_conformance → 6 passed, 0.17 s total.
  • The same binary 30× in a row with --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 warnings clean; cargo fmt --all --check clean.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fe14962b-f886-425c-bf5b-aa7b3cb7d5ef
Commits

Reviewing files that changed from the base of the PR and between 2047a68 and 7d9f711.

Files ignored due to path filters: 1

  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 5

  • CONTRIBUTING.md
  • crates/cello/Cargo.toml
  • crates/cello/asyncrt.rs
  • crates/cello/js.rs
  • crates/cello/tests/virtual_clock_conformance.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

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
ryuzdev force-pushed the tests/virtual-clock branch from cb3219e to 7d9f711 Compare November 22, 2026 09:46
@ryuzdev
ryuzdev merged commit be60758 into main Nov 22, 2026
7 checks passed
@ryuzdev
ryuzdev deleted the tests/virtual-clock branch November 22, 2026 09:58
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