From 5ad40226043160382b5f213240d9e351cfe76f4d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 19:54:22 -0800 Subject: [PATCH 1/3] chore(quest): claim quest/m1/poll-first/no-spawn/sim-tests.md Quest-Claim: f480abbb5fde904a From c1a5b3ce3bd32ebbe6ad948eb1fb5c5fb0c077b7 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 20:10:05 -0800 Subject: [PATCH 2/3] test(relay): run the in-memory relay tests on kio's simulator connection.rs and drain.rs move from paused tokio to #[kio::test]: their relay connections, session drivers, cluster, origins, and deciders run as kio::clock::sim tasks, with origins built from moq-net's driver instead of moq_tokio::origin::spawn. This finishes the no-spawn epic, so its quests are deleted and its rule and remaining spawns move into the m2 spawn audit. Co-Authored-By: Claude Opus 5.5 --- quest/m1/poll-first/README.md | 1 - quest/m1/poll-first/no-spawn/README.md | 60 -------------------- quest/m1/poll-first/no-spawn/sim-tests.md | 18 ------ quest/m2/net-wrap/README.md | 2 +- quest/m2/spawn-audit.md | 35 +++++++++--- quest/m3/video-web.md | 4 -- rs/AGENTS.md | 2 +- rs/moq-relay/tests/integration/connection.rs | 42 +++++++------- rs/moq-relay/tests/integration/drain.rs | 24 ++++---- rs/moq-relay/tests/integration/memory.rs | 42 ++++++++++---- 10 files changed, 94 insertions(+), 136 deletions(-) delete mode 100644 quest/m1/poll-first/no-spawn/README.md delete mode 100644 quest/m1/poll-first/no-spawn/sim-tests.md diff --git a/quest/m1/poll-first/README.md b/quest/m1/poll-first/README.md index 61c24bb8314..303a78e2085 100644 --- a/quest/m1/poll-first/README.md +++ b/quest/m1/poll-first/README.md @@ -76,4 +76,3 @@ and their alternatives: - [Generated async wrappers behind a feature](/quest/m1/poll-first/async-feature.md) - each library's `async fn` wrappers are generated from its `poll_*` signatures and compile only with its `async` feature - [Server::accept and Handshake::ok are kio machines](/quest/m1/poll-first/server-machines.md) - moq-net's `Server::accept` and `server::Handshake::ok` are `#[kio::machine]` `poll_*` methods with one-line async wrappers, like the other straight-line bodies converted in [moq-dev/moq#7284](https://github.com/moq-dev/moq/pull/7284) -- [Libraries spawn nothing](/quest/m1/poll-first/no-spawn/README.md) - moq-ffi, moq-stats, and moq-relay's cluster and auth run as polled `kio::Tasks` children instead of spawned tasks diff --git a/quest/m1/poll-first/no-spawn/README.md b/quest/m1/poll-first/no-spawn/README.md deleted file mode 100644 index 2a142fed161..00000000000 --- a/quest/m1/poll-first/no-spawn/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# Libraries spawn nothing - -## Goal - -moq-ffi, moq-stats, and moq-relay's cluster and auth decider spawn no tasks: -their background work runs as `kio::Tasks` children that the owner polls, -returned as a handle whose poll drives it. Only the edges spawn a root task: -binaries and the bindings' runtime. moq-relay's in-memory integration tests -(`rs/moq-relay/tests/integration/connection.rs`) run on kio's simulator -instead of paused tokio. - -## Plan - -Decided with the maintainer on 2026-10-25, replacing the m2 runtime trait -(spawn and time for tokio, browser, io_uring, and sim): - -- **Poll everywhere, no spawn.** A spawn trait keeps `'static` detached tasks - in the library, which poll-first rejects; `kio::Tasks` already gives a - library structured children with no runtime. Time is - `kio::clock`, so nothing is left for a runtime trait. - `rs/AGENTS.md` already treats `tokio::spawn` in a library as a smell. -- **No I/O seam.** I/O stays at moq-net's `transport::poll` traits and - moq-sock: tokio's readiness model and io_uring's completion model (the - kernel owns the buffer) can't share a zero-cost API. -- **Blocking work is out of scope.** OS threads for blocking capture, encode, - or file I/O are not async tasks and stay. - -✅ **Split into four children** (maintainer, 2026-11-01, D1 on -[moq-dev/moq#7519](https://github.com/moq-dev/moq/pull/7519)), landed in the -order of Required below. One PR could not hold them all, and two open PRs -already changed part of the scope: -[moq-dev/moq#7360](https://github.com/moq-dev/moq/pull/7360) (merged -2026-11-01) removed the auth decider loop and returns moq-stats' publisher from -`Producer::new`, and -[moq-dev/moq#7497](https://github.com/moq-dev/moq/pull/7497) rewrites moq-ffi's -`Task` and `Background` plumbing. Each child records its own decisions. - -Every child lists any spawn that has to stay, with why, in its PR. Public API: -constructors that spawned return a handle to poll or await instead. Each PR's -Impact section describes migration for the published crates whose API changes. -Wire: none. - -These spawns stay and belong to [the spawn audit](/quest/m2/spawn-audit.md): -`Critical`'s ACME renewal (`rs/moq-relay/src/relay.rs`) and web certificate -reload (`rs/moq-relay/src/web.rs`), the io_uring handoff in -`rs/moq-relay/src/connection.rs`, and moq-relay's web, shutdown, and uring -spawns. Each UniFFI call's task on the bindings' runtime stays too: that is the -binding boundary. So does moq-ffi's wake dispatch (decided 2026-11-03, -[moq-dev/moq#7720](https://github.com/moq-dev/moq/pull/7720)): a wake its root -raises for a parked host call runs on the blocking pool, so a host continuation -never runs inside the root. It owns no state and polls no background work. - -## Required - -- [The relay's in-memory tests run on kio's simulator](/quest/m1/poll-first/no-spawn/sim-tests.md) - `rs/moq-relay/tests/integration/connection.rs` runs on the simulator instead of paused tokio - -## Related - -- [The remaining spawns](/quest/m2/spawn-audit.md) - the same rule for every other library crate -- [Generated async wrappers](/quest/m1/poll-first/async-feature.md) - the poll-first sibling that gates the async layer diff --git a/quest/m1/poll-first/no-spawn/sim-tests.md b/quest/m1/poll-first/no-spawn/sim-tests.md deleted file mode 100644 index 065e5927f99..00000000000 --- a/quest/m1/poll-first/no-spawn/sim-tests.md +++ /dev/null @@ -1,18 +0,0 @@ -# [M] The relay's in-memory tests run on kio's simulator - -## Goal - -moq-relay's in-memory integration tests -(`rs/moq-relay/tests/integration/connection.rs`) run on kio's simulator -instead of paused tokio. - -## Plan - -This needs the cluster's and the admissions' work to be polled, which the -children it requires deliver. It also needs `moq_tokio::origin::spawn` and the -memory connect helper the tests use to run without tokio. moq-tokio belongs to -[the spawn audit](/quest/m2/spawn-audit.md) (m2), so this quest may move to -m2, or require the part of the spawn audit that converts those two helpers. -Decide that when it starts. - -Public API: none. Wire: none. diff --git a/quest/m2/net-wrap/README.md b/quest/m2/net-wrap/README.md index 85ac12834f5..59348758332 100644 --- a/quest/m2/net-wrap/README.md +++ b/quest/m2/net-wrap/README.md @@ -15,7 +15,7 @@ Compression is not a wrapper: it moves into moq-net as a track flag moq-flate, so moq-flate is out of scope. Non-goals: -- A runtime seam: libraries poll and spawn nothing ([Libraries spawn nothing](/quest/m1/poll-first/no-spawn/README.md)). +- A runtime seam: libraries poll and spawn nothing ([the remaining library spawns](/quest/m2/spawn-audit.md)). - The transport seam: custom transports implement moq-net's `transport::poll` traits ([native WebTransport](/quest/m1/quic-api/native-web.md) moves the last backend onto them). ## Plan diff --git a/quest/m2/spawn-audit.md b/quest/m2/spawn-audit.md index 564e37a7169..8aad08c51e8 100644 --- a/quest/m2/spawn-audit.md +++ b/quest/m2/spawn-audit.md @@ -2,14 +2,37 @@ ## Goal -Every async task spawn left in a library crate after -[Libraries spawn nothing](/quest/m1/poll-first/no-spawn/README.md) is either converted -to a `kio::Tasks` child its owner polls or listed with the reason it must stay. +Every async task spawn left in a library crate is either converted to a +`kio::Tasks` child its owner polls or listed with the reason it must stay. Blocking OS threads are out of scope. ## Plan -Planned 2026-10-25 with the maintainer as the follow-up to no-spawn. As of +Planned 2026-10-25 with the maintainer as the follow-up to no-spawn, the m1 epic +that converted moq-ffi, moq-stats, and moq-relay's cluster and auth decider and +moved the relay's in-memory tests onto kio's simulator. Its rule, decided with the +maintainer on 2026-10-25 in place of an m2 runtime trait: + +- **Poll everywhere, no spawn.** A spawn trait keeps `'static` detached tasks + in the library, which poll-first rejects; `kio::Tasks` gives a library + structured children with no runtime, and time is `kio::clock`. Only the edges + spawn a root task: binaries and the bindings' runtime. +- **No I/O seam.** I/O stays at moq-net's `transport::poll` traits and + moq-sock. +- **Blocking work is out of scope.** OS threads for blocking capture, encode, + or file I/O are not async tasks and stay. + +Spawns no-spawn kept for this audit to convert or list: `Critical`'s ACME +renewal (`rs/moq-relay/src/relay.rs`) and web certificate reload +(`rs/moq-relay/src/web.rs`), the io_uring handoff in +`rs/moq-relay/src/connection.rs`, and moq-relay's web, shutdown, and uring +spawns. Each UniFFI call's task on the bindings' runtime stays: that is the +binding boundary. So does moq-ffi's wake dispatch (decided 2026-11-03, +[moq-dev/moq#7720](https://github.com/moq-dev/moq/pull/7720)): a wake its root +raises for a parked host call runs on the blocking pool, so a host continuation +never runs inside the root. + +As of `main` today the spawning library crates include moq-tokio (connection, server, client), moq-relay (web, shutdown, uring), moq-mux's container consumer, moq-hls's server (its path follower and each @@ -38,7 +61,3 @@ server entry above): Public API: constructors that spawned return a handle to poll instead; an Impact migration note per published crate. Wire: none. - -## Required - -- [Libraries spawn nothing](/quest/m1/poll-first/no-spawn/README.md) - the rule and the pattern this applies diff --git a/quest/m3/video-web.md b/quest/m3/video-web.md index c51b20eaf3b..edcd680a54c 100644 --- a/quest/m3/video-web.md +++ b/quest/m3/video-web.md @@ -39,7 +39,3 @@ bump. rather than silently picking another. - **Out of scope:** replacing js/publish's or js/watch's internals with these backends. - -## Required - -- [Libraries spawn nothing](/quest/m1/poll-first/no-spawn/README.md) - library work polled by its owner, with no runtime to spawn on diff --git a/rs/AGENTS.md b/rs/AGENTS.md index e97608e7dc3..1a794683c33 100644 --- a/rs/AGENTS.md +++ b/rs/AGENTS.md @@ -57,7 +57,7 @@ Prefer poll. New logic is a `poll_*` with a generated `async` wrapper, not the o # Testing -- Tests are inline `#[cfg(test)] mod tests`, except full Client/Server session tests over a crate's shared mock harness, which go in its `tests/integration/` module. Time-dependent async tests call `tokio::time::pause()` first (moq-net uses `#[kio::test]` instead), unless they cross real networking that can't be mocked (sockets, smoke tests); those run on the wall clock and assert lower bounds. +- Tests are inline `#[cfg(test)] mod tests`, except full Client/Server session tests over a crate's shared mock harness, which go in its `tests/integration/` module. Time-dependent async tests call `tokio::time::pause()` first (moq-net and moq-relay's in-memory tests use `#[kio::test]` instead), unless they cross real networking that can't be mocked (sockets, smoke tests); those run on the wall clock and assert lower bounds. - Run tests through `just` (nextest), not `cargo test`: nextest kills a wedged test as TIMEOUT, cargo hangs forever. A test flagged SLOW is a bug to fix, not a threshold to raise. - `just check` and CI build and test the selected crates in one build at their default features, plus the off-by-default device features and, on Linux, the relay's `io-uring` feature. `just rs features` (nightly and release PRs) covers the feature matrix. Keep a feature gate around the dependency, not the logic, so the logic's tests stay in the merge gate. - Local checks compile only the host platform; Nightly and release PRs run `just rs windows` / `macos` on those hosts. diff --git a/rs/moq-relay/tests/integration/connection.rs b/rs/moq-relay/tests/integration/connection.rs index 1131818bf43..f30e267240a 100644 --- a/rs/moq-relay/tests/integration/connection.rs +++ b/rs/moq-relay/tests/integration/connection.rs @@ -1,5 +1,5 @@ //! A relay [`Connection`](moq_relay::Connection) over the in-memory transport: admission, -//! the cluster origin, and stats, with no socket and on Tokio's paused clock. +//! the cluster origin, and stats, with no socket and on kio's simulator. use std::time::Duration; @@ -7,18 +7,18 @@ use moq_net::stats; use crate::memory::{self, connect, newest}; -/// Long enough that only a hang reaches it; paused time skips straight there. +/// Long enough that only a hang reaches it; simulated time skips straight there. const TIMEOUT: Duration = Duration::from_secs(60); /// The relay preserves every legal QUIC-varint sequence, including values beyond /// JavaScript's exact number range, on each flavour used by the browser bindings. -#[tokio::test(start_paused = true)] +#[kio::test] async fn largest_quic_sequence_reaches_the_subscriber() { for alpn in ["moq-lite-02", "moq-lite-06", "moq-transport-22"] { let version = alpn.parse().unwrap(); let auth = memory::public(&["**"], &[], &[]); let cluster = memory::cluster(); - let publisher = moq_tokio::origin::spawn(); + let publisher = memory::origin(); let broadcast = publisher.create_broadcast("ladder").unwrap(); let info = moq_net::track::Info::default().with_timescale(moq_net::Timescale::MICRO); let track = broadcast.create_track("data", info).unwrap(); @@ -31,7 +31,7 @@ async fn largest_quic_sequence_reaches_the_subscriber() { ) .await .unwrap(); - let subscriber = moq_tokio::origin::spawn(); + let subscriber = memory::origin(); let _subscriber = connect( moq_net::Client::new().with_subscriber(subscriber.clone()), version, @@ -77,7 +77,7 @@ fn publish( moq_net::origin::Publication, moq_net::track::Producer, ) { - let origin = moq_tokio::origin::spawn(); + let origin = memory::origin(); let broadcast = origin.create_broadcast(name).expect("create broadcast"); broadcast.announce(Default::default()).expect("announce"); let info = moq_net::track::Info::default().with_timescale(moq_net::Timescale::MILLI); @@ -122,7 +122,7 @@ async fn assert_refused(result: Result) { /// A publisher whose grant covers only subscribing is refused during the handshake, /// instead of accepted to stream into a dropped session forever. Its SETUP's role /// says it publishes. -#[tokio::test(start_paused = true)] +#[kio::test] async fn subscribe_only_public_rejects_publisher_role() { let auth = memory::public(&[], &[], &["**"]); let (origin, _broadcast, _track) = publish("cam"); @@ -131,10 +131,10 @@ async fn subscribe_only_public_rejects_publisher_role() { } /// The same grant keeps a subscriber: the role gate refuses only the mismatched direction. -#[tokio::test(start_paused = true)] +#[kio::test] async fn subscribe_only_public_accepts_subscriber_role() { let auth = memory::public(&[], &[], &["**"]); - let client = moq_net::Client::new().with_subscriber(moq_tokio::origin::spawn()); + let client = moq_net::Client::new().with_subscriber(memory::origin()); let session = connect(client, newest(), &memory::cluster(), &auth) .await .expect("subscriber connects"); @@ -145,16 +145,16 @@ async fn subscribe_only_public_accepts_subscriber_role() { } /// The mirror: a subscriber whose grant covers only publishing is refused. -#[tokio::test(start_paused = true)] +#[kio::test] async fn publish_only_public_rejects_subscriber_role() { let auth = memory::public(&[], &["**"], &[]); - let client = moq_net::Client::new().with_subscriber(moq_tokio::origin::spawn()); + let client = moq_net::Client::new().with_subscriber(memory::origin()); assert_refused(connect(client, newest(), &memory::cluster(), &auth).await).await; } /// Two publish-only clients share one relay, and a subscriber sees both broadcasts: /// neither tears the other down. -#[tokio::test(start_paused = true)] +#[kio::test] async fn two_publish_only_clients_coexist() { let auth = memory::public(&["**"], &[], &[]); let cluster = memory::cluster(); @@ -178,7 +178,7 @@ async fn two_publish_only_clients_coexist() { .await .expect("beta connects"); - let origin = moq_tokio::origin::spawn(); + let origin = memory::origin(); let mut announced = origin.consume().announced(); let _subscriber = connect( moq_net::Client::new().with_subscriber(origin), @@ -197,10 +197,10 @@ async fn two_publish_only_clients_coexist() { /// The decider is asked about the path, query, and role the SETUP carried, and the /// grant it answers is rooted at that path: a publisher's broadcast reaches a root /// subscriber under it, frames and all. -#[tokio::test(start_paused = true)] +#[kio::test] async fn the_setup_path_reaches_the_decider_and_roots_the_grant() { let (auth, mut admissions) = moq_relay::auth::Auth::embedded("test"); - let decider = tokio::spawn(async move { + let decider = kio::clock::sim::spawn(async move { let mut seen = Vec::new(); while let Some(admission) = admissions.next().await { seen.push(admission.request.clone()); @@ -222,7 +222,7 @@ async fn the_setup_path_reaches_the_decider_and_roots_the_grant() { .await .expect("publisher connects"); - let origin = moq_tokio::origin::spawn(); + let origin = memory::origin(); let consumer = origin.consume(); let mut announced = consumer.announced(); let _subscriber = connect( @@ -267,11 +267,11 @@ async fn the_setup_path_reaches_the_decider_and_roots_the_grant() { /// The relay's stats count an admitted session while it is open and a refused one /// by its reason, under the default tier. -#[tokio::test(start_paused = true)] +#[kio::test] async fn stats_count_admitted_and_refused_sessions() { let mut config = moq_relay::stats::Config::default(); config.enabled = true; - let cluster = crate::spawn_cluster(moq_relay::cluster::Options::default().with_stats(config)); + let cluster = memory::spawn_cluster(moq_relay::cluster::Options::default().with_stats(config)); let registry = cluster.stats.clone(); let presence = || { registry @@ -283,13 +283,13 @@ async fn stats_count_admitted_and_refused_sessions() { }; let auth = memory::public(&[], &[], &["**"]); - let client = moq_net::Client::new().with_subscriber(moq_tokio::origin::spawn()); + let client = moq_net::Client::new().with_subscriber(memory::origin()); let session = connect(client, newest(), &cluster, &auth) .await .expect("subscriber connects"); kio::clock::timeout(TIMEOUT, async { while presence().active() != 1 { - tokio::task::yield_now().await; + kio::clock::sim::yield_now().await; } }) .await @@ -303,7 +303,7 @@ async fn stats_count_admitted_and_refused_sessions() { drop(session); kio::clock::timeout(TIMEOUT, async { while presence().active() != 0 { - tokio::task::yield_now().await; + kio::clock::sim::yield_now().await; } }) .await diff --git a/rs/moq-relay/tests/integration/drain.rs b/rs/moq-relay/tests/integration/drain.rs index ef54ceaba40..9391c0a819e 100644 --- a/rs/moq-relay/tests/integration/drain.rs +++ b/rs/moq-relay/tests/integration/drain.rs @@ -1,4 +1,4 @@ -//! The shutdown drain over moq-net's in-memory transport, on Tokio's paused clock. +//! The shutdown drain over moq-net's in-memory transport, on kio's simulator. //! //! The deadline closes every established session the drain still holds, however //! its GOAWAY is faring, and the drain returns only once each has recorded its end. @@ -38,7 +38,7 @@ async fn admit(observer: &shutdown::Observer, version: moq_net::Version, stalled let (client_link, relay_link) = memory::pair(config); let observer = observer.clone(); - tokio::spawn(async move { + drop(kio::clock::sim::spawn(async move { let server = moq_net::Server::new().with_versions(version.into()); let handshake = server .accept_request(moq_net::time::Instant::now(), relay_link) @@ -49,13 +49,13 @@ async fn admit(observer: &shutdown::Observer, version: moq_net::Version, stalled .with_shutdown(observer) .run() .await; - }); + })); let all = moq_auth::Pattern::all; let (lease, consumer) = lease::Producer::new(moq_auth::Grant::new(all(), all())); - tokio::spawn(async move { + drop(kio::clock::sim::spawn(async move { admissions.next().await.expect("an admission").grant(consumer); - }); + })); let (client, driver) = moq_net::Client::new() .with_versions(version.into()) .connect(moq_net::time::Instant::now(), client_link) @@ -65,7 +65,7 @@ async fn admit(observer: &shutdown::Observer, version: moq_net::Version, stalled // Polled only while `reading`, and never dropped: a dropped driver would close // the transport rather than leave it open and unread. let reading = Arc::new(AtomicBool::new(true)); - tokio::spawn({ + drop(kio::clock::sim::spawn({ let reading = reading.clone(); async move { let mut driver = std::pin::pin!(moq_net::time::run(driver)); @@ -75,9 +75,9 @@ async fn admit(observer: &shutdown::Observer, version: moq_net::Version, stalled }) .await } - }); + })); - // Paused time advances only once every task is idle, so the relay is + // Simulated time advances only once every task is idle, so the relay is // supervising the session by the time this returns. kio::clock::sleep(Duration::from_millis(1)).await; assert!( @@ -89,15 +89,15 @@ async fn admit(observer: &shutdown::Observer, version: moq_net::Version, stalled } /// Start the drain and return its end, which [`shutdown::Observer::drained`] reports. -fn drain(trigger: &shutdown::Trigger, observer: &shutdown::Observer) -> tokio::task::JoinHandle<()> { +fn drain(trigger: &shutdown::Trigger, observer: &shutdown::Observer) -> kio::clock::sim::JoinHandle<()> { trigger.start(); let observer = observer.clone(); - tokio::spawn(async move { observer.drained().await }) + kio::clock::sim::spawn(async move { observer.drained().await }) } /// A peer that ignores the GOAWAY is closed at the deadline, and the drain returns /// only after its lease recorded the shutdown. -#[tokio::test(start_paused = true)] +#[kio::test] async fn a_session_ignoring_the_goaway_is_closed_at_the_deadline() { for alpn in ["moq-lite-06", "moq-lite-03", "moq-transport-18"] { let (trigger, observer) = shutdown::Observer::new(WINDOW); @@ -129,7 +129,7 @@ async fn a_session_ignoring_the_goaway_is_closed_at_the_deadline() { /// A peer that stops reading leaves the relay's GOAWAY stuck on its stream, so the /// driver never arms its own timer. The drain deadline still closes the session and /// waits for its end. -#[tokio::test(start_paused = true)] +#[kio::test] async fn a_stalled_goaway_write_is_still_closed_at_the_deadline() { let (trigger, observer) = shutdown::Observer::new(WINDOW); let session = admit(&observer, "moq-lite-06".parse().unwrap(), true).await; diff --git a/rs/moq-relay/tests/integration/memory.rs b/rs/moq-relay/tests/integration/memory.rs index 1ec83a7e86f..a2b7c42b20d 100644 --- a/rs/moq-relay/tests/integration/memory.rs +++ b/rs/moq-relay/tests/integration/memory.rs @@ -1,7 +1,7 @@ -//! A relay [`Connection`] over moq-net's in-memory transport. +//! A relay [`Connection`] over moq-net's in-memory transport, on kio's simulator. //! -//! No sockets, so a test on Tokio's paused clock never waits on the host: the clock -//! only advances once every message in flight has landed. +//! No sockets and no Tokio: every task runs on [`kio::clock::sim`], whose clock only +//! advances once every message in flight has landed, so a test never waits on the host. #[cfg(feature = "test-support")] use moq_net::transport::memory; @@ -16,8 +16,8 @@ pub fn newest() -> moq_net::Version { /// Dial a relay serving `cluster` through `auth` over a fresh in-memory link, as /// `client` speaking `version`. /// -/// The relay's half runs as [`Connection::run`] on its own task, reported to the -/// decider as QUIC. Lite 05+ answers SETUP before the verdict, so a refused session +/// The relay's half runs as [`Connection::run`] on its own simulator task, reported +/// to the decider as QUIC. Lite 05+ answers SETUP before the verdict, so a refused session /// may connect and then close. #[cfg(feature = "test-support")] pub async fn connect( @@ -31,20 +31,20 @@ pub async fn connect( let (client_link, relay_link) = memory::pair(config); let (cluster, auth) = (cluster.clone(), auth.clone()); - tokio::spawn(async move { + drop(kio::clock::sim::spawn(async move { let server = moq_net::Server::new().with_versions(version.into()); let Ok(handshake) = server.accept_request(moq_net::time::Instant::now(), relay_link).await else { return; }; let request = Accepted::new(handshake, moq_auth::Transport::Quic); Connection::new(request, cluster, auth).run().await; - }); + })); let (session, driver) = client .with_versions(version.into()) .connect(moq_net::time::Instant::now(), client_link) .await?; - tokio::spawn(moq_net::time::run(driver)); + drop(kio::clock::sim::spawn(moq_net::time::run(driver))); Ok(session) } @@ -62,8 +62,30 @@ pub fn public(public: &[&str], publish: &[&str], subscribe: &[&str]) -> auth::Au .expect("auth init") } -/// A standalone cluster with default options. +/// A standalone cluster with default options, driven on the simulator. #[cfg(feature = "test-support")] pub fn cluster() -> cluster::Cluster { - crate::spawn_cluster(cluster::Options::default()) + spawn_cluster(cluster::Options::default()) +} + +/// Build a cluster and drive it on a simulator task, as [`crate::spawn_cluster`] +/// does on Tokio. A failed driver panics the run. +#[cfg(feature = "test-support")] +pub fn spawn_cluster(options: cluster::Options) -> cluster::Cluster { + let (cluster, driver) = cluster::Cluster::new(options).expect("cluster init"); + drop(kio::clock::sim::spawn(async move { + if let Err(err) = driver.run().await { + panic!("cluster driver failed: {err:#}"); + } + })); + cluster +} + +/// An origin whose driver runs on a simulator task, as `moq_tokio::origin::spawn` +/// does on Tokio. +#[cfg(feature = "test-support")] +pub fn origin() -> moq_net::origin::Producer { + let (origin, driver) = moq_net::origin::Producer::new(Default::default()); + drop(kio::clock::sim::spawn(moq_net::time::run(driver))); + origin } From 7457804799f31ea1567ecfc5c10dfb91e8b3bd96 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 21:24:50 -0800 Subject: [PATCH 3/3] test(relay): let the stats polls advance simulated time The stats test's `presence().active()` loops yielded with `kio::clock::sim::yield_now`, which keeps the task runnable, so the simulator never jumps the clock and the enclosing `TIMEOUT` could never fire: a broken count spun until nextest killed the test. Sleep 1ms instead so a wrong count fails at `TIMEOUT`. Co-Authored-By: Claude Opus 5.5 --- rs/moq-relay/tests/integration/connection.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rs/moq-relay/tests/integration/connection.rs b/rs/moq-relay/tests/integration/connection.rs index f30e267240a..d53bbe80c93 100644 --- a/rs/moq-relay/tests/integration/connection.rs +++ b/rs/moq-relay/tests/integration/connection.rs @@ -289,7 +289,7 @@ async fn stats_count_admitted_and_refused_sessions() { .expect("subscriber connects"); kio::clock::timeout(TIMEOUT, async { while presence().active() != 1 { - kio::clock::sim::yield_now().await; + kio::clock::sleep(Duration::from_millis(1)).await; } }) .await @@ -303,7 +303,7 @@ async fn stats_count_admitted_and_refused_sessions() { drop(session); kio::clock::timeout(TIMEOUT, async { while presence().active() != 0 { - kio::clock::sim::yield_now().await; + kio::clock::sleep(Duration::from_millis(1)).await; } }) .await