diff --git a/c/moq/test/probe.c b/c/moq/test/probe.c index 6ca21f6ee1f..db6d9316443 100644 --- a/c/moq/test/probe.c +++ b/c/moq/test/probe.c @@ -362,10 +362,10 @@ int main(void) moq_track_consumer *consumer = await(&subscribed, "subscribe_track"); moq_task_free(task); - /* Freeing a pending task cancels the read, and its callback never runs. */ + /* Freeing a pending task cancels the read, and its callback never runs, even while the + * next read below pumps the loop. */ result cancelled = {0}; task = moq_track_consumer_read_frame(consumer, on_frame, &cancelled); - CHECK(!pump(&cancelled.done, 50)); moq_task_free(task); /* The consumer survives the cancelled read and delivers the next frame. */ diff --git a/cpp/moq/test/probe.cpp b/cpp/moq/test/probe.cpp index e4f325ebade..f5fc8e0343a 100644 --- a/cpp/moq/test/probe.cpp +++ b/cpp/moq/test/probe.cpp @@ -347,7 +347,7 @@ int main() // Cancel a read that has nothing to deliver yet. auto pending = consumer->read_frame(); - CHECK(pending.wait_for(50ms) == std::future_status::timeout); + CHECK(pending.wait_for(0ms) == std::future_status::timeout); CHECK(pending.valid()); pending.cancel(); CHECK(!pending.valid()); @@ -396,7 +396,7 @@ int main() Latch done; std::optional received; auto abandoned = read_one(consumer, received, done); - CHECK(!done.wait_for(50ms)); + CHECK(!done.wait_for(0ms)); abandoned.handle.destroy(); } diff --git a/demo/carla/sim/tests/test_runtime.py b/demo/carla/sim/tests/test_runtime.py index 2280f25b990..e6d30ed9d7f 100644 --- a/demo/carla/sim/tests/test_runtime.py +++ b/demo/carla/sim/tests/test_runtime.py @@ -611,10 +611,21 @@ def test_session_announces_after_populating_tracks() -> None: assert calls == ["status", "announce"] -def test_a_driver_keeps_the_world_stepping_with_nobody_watching() -> None: +async def expect_held(session: runtime.TruckSession, held: set[str]) -> None: + """Let the session's tasks run until the world's holds are `held`.""" + for _ in range(10): + if session._clock.held == held: + return + await asyncio.sleep(0) + pytest.fail(f"holds never became {held}, still {session._clock.held}") + + +def test_a_driver_keeps_the_world_stepping_with_nobody_watching(monkeypatch: pytest.MonkeyPatch) -> None: """Video demand and the lease are independent; the gate must hold for both.""" async def scenario() -> None: + # Time stands still, so only the watchdog command below ends the lease. + monkeypatch.setattr(asyncio.get_running_loop(), "time", lambda: 0.0) commands = asyncio.Queue() commands.put_nowait( Command(kind="drive", driver_id="holder", session="holder", sequence=1, state=DriveState(throttle=0.5)) @@ -631,17 +642,17 @@ async def scenario() -> None: session._actuate = lambda: None session._publish = lambda: None - with contextlib.suppress(asyncio.TimeoutError): - await asyncio.wait_for(session._loop(), timeout=0.1) - - assert session._clock.held == {"drive:truck1"} - - # The watchdog hands the truck back, and the hold goes with the lease. - session._commands.put_nowait(Command(kind="watchdog_expired")) - with contextlib.suppress(asyncio.TimeoutError): - await asyncio.wait_for(session._loop(), timeout=0.1) + task = asyncio.create_task(session._loop()) + try: + await expect_held(session, {"drive:truck1"}) - assert session._clock.held == set() + # The watchdog hands the truck back, and the hold goes with the lease. + session._commands.put_nowait(Command(kind="watchdog_expired")) + await expect_held(session, set()) + finally: + task.cancel() + with contextlib.suppress(asyncio.CancelledError): + await task asyncio.run(scenario()) @@ -690,20 +701,13 @@ async def scenario() -> None: session._status = DemandPublisher() watcher = asyncio.create_task(session._watch_status_demand()) - async def expect_held(held: set[str]) -> None: - for _ in range(10): - if session._clock.held == held: - return - await asyncio.sleep(0) - pytest.fail(f"holds never became {held}, still {session._clock.held}") - try: session._status.use.set() - await expect_held({"status:truck1"}) + await expect_held(session, {"status:truck1"}) session._status.unuse.set() - await expect_held(set()) + await expect_held(session, set()) session._status.use.set() - await expect_held({"status:truck1"}) + await expect_held(session, {"status:truck1"}) finally: watcher.cancel() with contextlib.suppress(asyncio.CancelledError): diff --git a/quest/m1/mock-clock-tests/README.md b/quest/m1/mock-clock-tests/README.md index 92beb185a5e..5ae00211c7e 100644 --- a/quest/m1/mock-clock-tests/README.md +++ b/quest/m1/mock-clock-tests/README.md @@ -1,13 +1,12 @@ -# [XL] Tests run on a mocked clock +# [L] Tests run on a mocked clock ## Goal No test proves that nothing happened by waiting, sleeps to let things settle, or asserts on elapsed real time. Each one runs on a paused, -simulated, or `Manual` clock, or awaits the event it means. About 300 tests -do one of these today, most of them behind a dozen shared helpers. Tests -that only wait for progress under a generous timeout, and tests on real -sockets, devices, or processes, stay on the real clock. +simulated, or `Manual` clock, or awaits the event it means. Tests that only +wait for progress under a generous timeout, and tests on real sockets, +devices, or processes, stay on the real clock. ## Plan @@ -21,7 +20,7 @@ test's clock): - ✅ m1, while the guards that stop new ones (the runtime guards and the `REVIEW.md` rule) landed in m0. -Rules every child keeps: +Rules the remaining work keeps: - Fix the shared helper first, then its callers. A helper that resolves `undefined` when a timeout runs out becomes one that advances a mocked @@ -29,13 +28,36 @@ Rules every child keeps: - Never replace one real wait with a shorter or longer one, or with a quiet window. - Fix a test and its siblings in other languages together. -- Each JS child removes the bare `hostTime();` opt-outs in its area, so the - `bun test` guard (`js/clock/src/preload.ts`) covers the converted tests. An - opt-out with a trailing reason comment is real I/O and stays. -- Each Rust child removes the `kio::clock::host_time()` calls in the - tests it converts, so `just rs test`'s host-timer guard covers them. A test - over a real QUIC endpoint or ICE agent is exempt without one, since those - transports allow host timers themselves. - -The counts come from a heuristic scan on 2026-11-06; re-scan each area -before starting, since tests land and move. +- An opt-out with a trailing reason comment (`hostTime(); // a real HTTP + server`, `kio::clock::host_time(); // real SRT sockets`) is real I/O and + stays. A bare one marks a test still to convert: remove it with the + conversion, so the `bun test` guard (`js/clock/src/preload.ts`) or + `just rs test`'s host-timer guard covers the test. A test over a real QUIC + endpoint or ICE agent needs none, since those transports allow host timers + themselves. + +What remains, from a scan on 2026-11-07; re-scan before starting, since +tests land and move: + +- **moq-relay's TCP-only tests**, the seven bare `kio::clock::host_time()` + calls in `tests/integration/auth_lifetime.rs` (4), `session_revalidate.rs` + (2), and `socket_auth.rs` (1). They wait out real re-check cadences and the + handshake deadline over TCP, bound a close by a real budget ("well inside + the cadence"), and poll listings on kio sleeps. The relay runs on the test + runtime, so an installed `kio::clock::Manual` can own its timers while the + sockets stay real: a push then proves its close with the clock standing + still, and a cadence passes by `advance`. `wait_listed` and `assert_closed` + need awaited events first. `socket_auth`'s test waits only for progress, + so find which relay timer fires there. +- **moq-ffi's `video_encoder_follows_a_shrinking_grant`**, which polls + `applied_bitrate()` every 10 ms while the follow thread retunes the + encoder. The applied target lives in `VideoProducer` under the rendition's + one lock, so the test needs an event from the follower, not a second + channel beside that lock. +- **The OBS plugin tests** in `cpp/obs/test`, which neither runtime guard + sees. `moq-output-test.cpp` and `moq-source-test.cpp` sleep 50 to 100 ms, + then check that no further signal or frame arrived; `obs-moq-test.cpp` + proves a parked `accept` by waiting 50 ms; `moq-dock-stop-test.cpp` + asserts `20ms <= elapsed < 400ms` around a worker that sleeps 30 ms. Each + needs an event from the plugin, such as its worker joining or the bridge + observing the close, instead of a window. diff --git a/rs/moq-auth/src/mesh/contract_tests.rs b/rs/moq-auth/src/mesh/contract_tests.rs index 569d63b6d48..6f3f043fc5b 100644 --- a/rs/moq-auth/src/mesh/contract_tests.rs +++ b/rs/moq-auth/src/mesh/contract_tests.rs @@ -183,11 +183,18 @@ async fn refresh_issues_a_new_token_until_revoked() { #[tokio::test] async fn renew_refreshes_before_expiry() { - kio::clock::host_time(); - let mesh = Mesh::with_ttl(Duration::from_secs(3)).await; + // A clock only the test moves, which the coordinator reads too; the HTTP between them is real. + let clock = kio::clock::Manual::new().install(&tokio::runtime::Handle::current()); + let ttl = Duration::from_secs(3); + let mesh = Mesh::with_ttl(ttl).await; let device = mesh.device(); let enrollment = device.enroll(&mesh.key(true), None).await.unwrap(); - let renewed = device.renew(&enrollment).await.unwrap(); + let mut renew = std::pin::pin!(device.renew(&enrollment)); + // The first poll arms the wait for two thirds of the token's life, before any request. + let mut cx = std::task::Context::from_waker(std::task::Waker::noop()); + assert!(std::future::Future::poll(renew.as_mut(), &mut cx).is_pending()); + clock.advance(ttl * 2 / 3); + let renewed = renew.await.unwrap(); assert!(kio::clock::wall() < enrollment.expires); assert!(renewed.expires > enrollment.expires); } @@ -218,7 +225,7 @@ async fn only_an_issued_challenge_is_accepted() { #[tokio::test] async fn renew_retries_a_transient_refusal() { - kio::clock::host_time(); + kio::clock::host_time(); // real HTTP, and the backoff is armed only after its refusal use wiremock::matchers::{method, path}; use wiremock::{Mock, MockServer, ResponseTemplate}; diff --git a/rs/moq-cli/src/archive.rs b/rs/moq-cli/src/archive.rs index a728a8c0b77..33b76a8e644 100644 --- a/rs/moq-cli/src/archive.rs +++ b/rs/moq-cli/src/archive.rs @@ -385,9 +385,8 @@ mod tests { /// `export archive` records each broadcast announced under its prefix into its own /// `/@`, and leaves out what is announced elsewhere. - #[tokio::test] + #[tokio::test(start_paused = true)] async fn each_broadcast_records_under_its_own_key_prefix() { - kio::clock::host_time(); let dir = tempfile::tempdir().unwrap(); let url = Url::from_directory_path(dir.path()).unwrap(); @@ -482,9 +481,8 @@ mod tests { /// `import archive` republishes a recording `export archive` wrote under the given name and /// instance, serving its stored groups. - #[tokio::test] + #[tokio::test(start_paused = true)] async fn an_exported_broadcast_imports() { - kio::clock::host_time(); let dir = tempfile::tempdir().unwrap(); let url = Url::from_directory_path(dir.path()).unwrap(); diff --git a/rs/moq-cli/src/hls.rs b/rs/moq-cli/src/hls.rs index 510bab1aca5..2408cd6bfc2 100644 --- a/rs/moq-cli/src/hls.rs +++ b/rs/moq-cli/src/hls.rs @@ -497,9 +497,8 @@ mod test { /// An announced import that fails, here on a timestamp reset, aborts its tracks and catalog /// with the cause, so subscribers see the failure rather than a dropped producer. - #[tokio::test] + #[tokio::test(start_paused = true)] async fn a_failed_import_aborts_its_tracks() { - kio::clock::host_time(); use moq_mux::container::{Frame, fmp4::Muxer}; let dir = tempfile::tempdir().unwrap(); diff --git a/rs/moq-cli/src/main.rs b/rs/moq-cli/src/main.rs index 0a8a4d2590b..b46fab21382 100644 --- a/rs/moq-cli/src/main.rs +++ b/rs/moq-cli/src/main.rs @@ -1613,7 +1613,6 @@ mod tests { /// A raw TCP bind is a complete server side even when no QUIC bind is set. #[tokio::test(start_paused = true)] async fn tcp_only_moq_side_starts_a_server() { - kio::clock::host_time(); let invocation = Invocation::try_parse_from([ "moq", "--listen-tcp-bind", diff --git a/rs/moq-cli/src/play/headless.rs b/rs/moq-cli/src/play/headless.rs index c7f620720f8..442c69289ab 100644 --- a/rs/moq-cli/src/play/headless.rs +++ b/rs/moq-cli/src/play/headless.rs @@ -154,9 +154,8 @@ mod tests { /// A run that ends still writes its final sample, with nothing it could not /// measure filled in. - #[tokio::test] + #[tokio::test(start_paused = true)] async fn metrics_write_a_final_sample() { - kio::clock::host_time(); let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("play.ndjson"); let producer = moq_tokio::origin::spawn(); diff --git a/rs/moq-ffi/src/test.rs b/rs/moq-ffi/src/test.rs index 4784c2ffcf8..bb14f320d4d 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -3336,7 +3336,6 @@ fn audio_rejects_bad_init_bytes() { /// the announcement. #[tokio::test] async fn a_hidden_route_is_invisible_until_announced() { - kio::clock::host_time(); let origin = MoqOriginProducer::new(MoqOriginConfig::default()); let consumer = origin.consume(); let route = origin.route("live".into(), hidden()).unwrap(); @@ -6282,13 +6281,11 @@ async fn follow_hands_out_a_takeover_once(dynamic_at: &str) { #[tokio::test] async fn follow_hands_out_a_takeover_once_while_resolving() { - kio::clock::host_time(); follow_hands_out_a_takeover_once("").await; } #[tokio::test] async fn follow_hands_out_a_held_takeover_once() { - kio::clock::host_time(); follow_hands_out_a_takeover_once("live").await; } @@ -6420,7 +6417,6 @@ async fn an_instance_pins_request_and_follow() { /// clock that nothing comes past the origin's update hold either. #[tokio::test] async fn follow_waits_for_another_instance_after_a_dropped_takeover() { - kio::clock::host_time(); let origin = MoqOriginProducer::new(MoqOriginConfig::default()); let dynamic = serve(&origin, "live"); let followed = origin.consume().follow("live".into(), None).unwrap(); diff --git a/rs/moq-hls/src/export/mod.rs b/rs/moq-hls/src/export/mod.rs index 143f1d1028a..3a898e25dce 100644 --- a/rs/moq-hls/src/export/mod.rs +++ b/rs/moq-hls/src/export/mod.rs @@ -947,7 +947,6 @@ mod tests { // nothing numbers their segments. Once it does, every rendition is added. #[tokio::test(start_paused = true)] async fn renditions_wait_for_the_join_interval() { - kio::clock::host_time(); let origin = produce_origin(); let broadcast = origin .route("live", moq_net::origin::RouteOptions::default()) @@ -1032,7 +1031,6 @@ mod tests { // and makes every recording cursor see a Removed followed by an Added. #[tokio::test(start_paused = true)] async fn estimate_only_catalog_update_keeps_the_rendition() { - kio::clock::host_time(); let origin = produce_origin(); let _broadcast = origin .route("live", moq_net::origin::RouteOptions::default()) @@ -1103,7 +1101,6 @@ mod tests { // (its timescale derives from the framerate) and churn every recording cursor mid-stream. #[tokio::test(start_paused = true)] async fn estimated_framerate_keeps_the_rendition() { - kio::clock::host_time(); let origin = produce_origin(); let _broadcast = origin .route("live", moq_net::origin::RouteOptions::default()) @@ -1168,7 +1165,6 @@ mod tests { // longer matches. #[tokio::test(start_paused = true)] async fn decoder_config_change_rebuilds_the_rendition() { - kio::clock::host_time(); let origin = produce_origin(); let _broadcast = origin .route("live", moq_net::origin::RouteOptions::default()) @@ -1232,9 +1228,8 @@ mod tests { // The whole fetch-on-demand path in process: a broadcast publishes media through the // catalog (which declares its join interval), the Broadcaster renders playlists from the // groups' timestamps, and a segment request fetches and transmuxes exactly its groups. - #[tokio::test] + #[tokio::test(start_paused = true)] async fn master_lists_only_playable_renditions() { - kio::clock::host_time(); let origin = produce_origin(); let broadcast = origin .route("live", moq_net::origin::RouteOptions::default()) @@ -1244,16 +1239,12 @@ mod tests { let mut media = video(&catalog, broadcast.broadcast(), "video0", video_config()); let broadcaster = Broadcaster::spawned(crate::resolved(&origin, "live").await, Config::default()); - let rendition = kio::clock::timeout(Duration::from_secs(5), async { - loop { - if let Some(rendition) = broadcaster.rendition(Kind::Video, "video0") { - break rendition; - } - tokio::task::yield_now().await; - } - }) - .await - .expect("rendition discovered from the catalog"); + let added = kio::clock::timeout(Duration::from_secs(5), broadcaster.renditions().next()) + .await + .expect("rendition discovered from the catalog"); + let Ok(Some(renditions::Event::Added(rendition))) = added else { + panic!("expected an Added event"); + }; assert!( rendition.media_playlist(None).unwrap().is_none(), @@ -1370,7 +1361,7 @@ mod tests { media.set(disabled).unwrap(); kio::clock::timeout(Duration::from_secs(5), async { while listed() { - tokio::task::yield_now().await; + kio::clock::sleep(Duration::from_millis(10)).await; } }) .await @@ -1873,9 +1864,8 @@ mod tests { // A reconfigure that changes the init bytes changes the init URL, so a cache can never hand a // player the previous init under the new one. The old URL keeps naming the old bytes while the // playlist still lists the segments muxed under them. - #[tokio::test] + #[tokio::test(start_paused = true)] async fn a_reconfigure_versions_the_init_url() { - kio::clock::host_time(); let origin = produce_origin(); let broadcast = origin .route("live", moq_net::origin::RouteOptions::default()) @@ -2166,9 +2156,8 @@ mod tests { /// Indexing reads every group of the media, but a stats session on the source's origin /// counts only the catalog and what a client fetches. - #[tokio::test] + #[tokio::test(start_paused = true)] async fn a_metered_source_counts_only_what_clients_fetch() { - kio::clock::host_time(); let origin = produce_origin(); let broadcast = origin .route("live", moq_net::origin::RouteOptions::default()) @@ -2678,9 +2667,8 @@ mod tests { } // A finished broadcast renders a static presentation. - #[tokio::test] + #[tokio::test(start_paused = true)] async fn dash_manifest_turns_static_when_finished() { - kio::clock::host_time(); let origin = produce_origin(); let broadcast = origin .route("live", moq_net::origin::RouteOptions::default()) @@ -3193,14 +3181,13 @@ mod tests { } async fn until_finished(rendition: &Rendition) { - let deadline = kio::clock::now() + Duration::from_secs(5); - loop { - if rendition.snapshot().finished { - return; + kio::clock::timeout(Duration::from_secs(5), async { + while !rendition.snapshot().finished { + kio::clock::sleep(Duration::from_millis(10)).await; } - assert!(kio::clock::now() < deadline, "the playlist did not end"); - tokio::task::yield_now().await; - } + }) + .await + .expect("the playlist did not end"); } /// A sibling-media fixture: the catalog broadcast `live` lists `video0`, and its media lives in diff --git a/rs/moq-hls/src/import.rs b/rs/moq-hls/src/import.rs index db100a7c0ae..dd5b7cded9f 100644 --- a/rs/moq-hls/src/import.rs +++ b/rs/moq-hls/src/import.rs @@ -2699,7 +2699,6 @@ mod tests { /// since the first placed the clock. A fresh offset would shift it by its own arrival. #[tokio::test(start_paused = true)] async fn a_replacement_importer_keeps_the_offset() { - kio::clock::host_time(); let (init, fragments) = fmp4_parts(2); let mut broadcast = moq_net::broadcast::Info::new().produce(); let consumer = broadcast.consume(); diff --git a/rs/moq-relay/src/web.rs b/rs/moq-relay/src/web.rs index cbafb369f80..1cb9c5de0d5 100644 --- a/rs/moq-relay/src/web.rs +++ b/rs/moq-relay/src/web.rs @@ -2440,7 +2440,7 @@ mod tests { /// sockets, so this runs on the wall clock and bounds the answer from below. #[tokio::test] async fn an_unanswered_http_admission_is_refused_at_the_timeout() { - kio::clock::host_time(); + kio::clock::host_time(); // real HTTP sockets use tokio::io::{AsyncReadExt, AsyncWriteExt}; let timeout = std::time::Duration::from_millis(200); diff --git a/rs/moq-relay/tests/integration/shutdown_signal.rs b/rs/moq-relay/tests/integration/shutdown_signal.rs index 4127f328288..a1c505c62ba 100644 --- a/rs/moq-relay/tests/integration/shutdown_signal.rs +++ b/rs/moq-relay/tests/integration/shutdown_signal.rs @@ -70,7 +70,7 @@ fn run_test + 'static>(test: fn() -> F) { #[test] fn sigint_drains_sessions_before_exiting() { - kio::clock::host_time(); + kio::clock::host_time(); // a real relay on real sockets let _sigint = SIGINT.lock().unwrap_or_else(|e| e.into_inner()); run_test(sigint_drains_sessions_before_exiting_inner); } @@ -110,7 +110,7 @@ fn a_failed_startup_leaves_the_signals_alone() { /// drains on its own trigger. #[test] fn an_embedder_owns_the_signals() { - kio::clock::host_time(); + kio::clock::host_time(); // a real relay on real sockets const CHILD: &str = "MOQ_RELAY_EMBEDDER_SIGNALS_CHILD"; if std::env::var_os(CHILD).is_some() { run_test(a_relay_without_signals_leaves_sigint_alone_inner); @@ -132,7 +132,7 @@ fn an_embedder_owns_the_signals() { #[test] fn a_session_arriving_mid_drain_gets_what_is_left() { - kio::clock::host_time(); + kio::clock::host_time(); // a real relay on real sockets run_test(a_session_arriving_mid_drain_gets_what_is_left_inner); } @@ -143,13 +143,13 @@ fn a_drain_ends_once_every_session_leaves() { #[test] fn a_trigger_before_run_keeps_the_deadline() { - kio::clock::host_time(); + kio::clock::host_time(); // a real relay on real sockets run_test(a_trigger_before_run_keeps_the_deadline_inner); } #[test] fn a_reconnecting_client_rides_out_a_restart() { - kio::clock::host_time(); + kio::clock::host_time(); // a real relay on real sockets run_test(a_reconnecting_client_rides_out_a_restart_inner); } diff --git a/rs/moq-rtmp/src/server.rs b/rs/moq-rtmp/src/server.rs index ffc4990937d..87c948fae69 100644 --- a/rs/moq-rtmp/src/server.rs +++ b/rs/moq-rtmp/src/server.rs @@ -2800,7 +2800,7 @@ mod tests { /// until it leaves. #[tokio::test] async fn a_reconnect_replaces_the_stale_publish() { - kio::clock::host_time(); + kio::clock::host_time(); // real RTMP over TCP let mut server = Server::bind("127.0.0.1:0".parse().unwrap()).await.unwrap(); let addr = server.local_addr().unwrap(); let origin = moq_tokio::origin::spawn(); diff --git a/rs/moq-rtsp/src/client.rs b/rs/moq-rtsp/src/client.rs index b194e6eca82..2ea8bb7318a 100644 --- a/rs/moq-rtsp/src/client.rs +++ b/rs/moq-rtsp/src/client.rs @@ -1046,7 +1046,7 @@ mod tests { /// far ahead as it paused, which continues the timeline rather than jumping it. #[tokio::test] async fn a_paused_stream_is_not_a_jump() { - kio::clock::host_time(); + kio::clock::host_time(); // real RTSP sockets, and the pause is real time let server = Server::bind(vec![Media::H264 { sprop: true }]).await; let (broadcast, catalog) = broadcast(); let mut client = Client::new(server.url()).unwrap(); diff --git a/rs/moq-srt/src/server.rs b/rs/moq-srt/src/server.rs index 8c008bd2b2c..836253deddd 100644 --- a/rs/moq-srt/src/server.rs +++ b/rs/moq-srt/src/server.rs @@ -1198,7 +1198,7 @@ mod tests { /// task and its socket until the follow runs out. #[tokio::test] async fn a_caller_hanging_up_during_the_follow_ends_the_egress() { - kio::clock::host_time(); + kio::clock::host_time(); // real SRT sockets let (origin, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::default()); tokio::spawn(moq_net::time::run(driver)); let mut live = Instance::publish(&origin, "a.aac"); diff --git a/rs/moq-tokio/src/server.rs b/rs/moq-tokio/src/server.rs index 914f0df6e8c..e1ed4b8987b 100644 --- a/rs/moq-tokio/src/server.rs +++ b/rs/moq-tokio/src/server.rs @@ -2715,7 +2715,7 @@ mod tests { #[cfg(all(feature = "uds", unix))] #[tokio::test] async fn unix_listener_serves_the_configured_publisher() { - kio::clock::host_time(); + kio::clock::host_time(); // a real Unix socket use rand::RngExt; // macOS caps AF_UNIX paths near 104 bytes and the system temp dir is long, diff --git a/rs/moq-tokio/src/tcp.rs b/rs/moq-tokio/src/tcp.rs index d5f634c14c1..fe9d68488d9 100644 --- a/rs/moq-tokio/src/tcp.rs +++ b/rs/moq-tokio/src/tcp.rs @@ -663,7 +663,7 @@ mod tests { /// through to the loopback listener within the stagger delay. #[tokio::test] async fn failover_recovers_from_blackhole_candidate() { - kio::clock::host_time(); + kio::clock::host_time(); // a real dial that blackholes let listener = Listener::bind("127.0.0.1:0".parse().unwrap()) .await .expect("bind listener") diff --git a/rs/moq-tokio/src/websocket.rs b/rs/moq-tokio/src/websocket.rs index 1670aba1fb0..3e26926ab96 100644 --- a/rs/moq-tokio/src/websocket.rs +++ b/rs/moq-tokio/src/websocket.rs @@ -874,31 +874,31 @@ mod tests { #[tokio::test] async fn tls_host_name_override_dials_url_address() { - kio::clock::host_time(); + kio::clock::host_time(); // real TLS over loopback check_tls_authority("127.0.0.1", false, Some("relay.example")).await; } #[tokio::test] async fn fixed_addresses_keep_tls_name_and_request_host() { - kio::clock::host_time(); + kio::clock::host_time(); // real TLS over loopback check_tls_authority("relay.example", true, None).await; } #[tokio::test] async fn ipv6_literal() { - kio::clock::host_time(); + kio::clock::host_time(); // real TLS over loopback check_tls_authority("[::1]", false, None).await; } #[tokio::test] async fn ipv6_literal_fixed_addresses() { - kio::clock::host_time(); + kio::clock::host_time(); // real TLS over loopback check_tls_authority("[::1]", true, None).await; } #[tokio::test] async fn ipv6_tls_host_name_override() { - kio::clock::host_time(); + kio::clock::host_time(); // real TLS over loopback check_tls_authority("[::1]", false, Some("::1")).await; } diff --git a/rs/moq-transcode/src/lib.rs b/rs/moq-transcode/src/lib.rs index 759436718ac..d62ab2fa77b 100644 --- a/rs/moq-transcode/src/lib.rs +++ b/rs/moq-transcode/src/lib.rs @@ -1019,7 +1019,6 @@ mod tests { /// do have to keep serving, and the passthrough entry has to follow. #[tokio::test] async fn ladder_follows_a_source_resize() { - kio::clock::host_time(); let mut source = source_catalog(640, 360); let config = Config { diff --git a/rs/moq-video/src/decode/consumer.rs b/rs/moq-video/src/decode/consumer.rs index 5785c8b2ca4..fcb93fbb8a8 100644 --- a/rs/moq-video/src/decode/consumer.rs +++ b/rs/moq-video/src/decode/consumer.rs @@ -988,7 +988,6 @@ mod tests { #[cfg(not(apple))] #[tokio::test] async fn a_cancelled_read_resumes_the_flush_in_flight() { - kio::clock::host_time(); probe::prepare_blocking_flush(); let broadcast = moq_net::broadcast::Info::new().produce(); let track = broadcast @@ -1230,7 +1229,6 @@ mod tests { /// then the max-delay decoder's once it has decoded the sweep before them. #[tokio::test] async fn a_cold_join_hands_over_to_the_max_delay_decoder() { - kio::clock::host_time(); let (broadcast, mut track) = live_track(); let published = track.clone(); group(&mut track, 0, &[0, 1, 2, 3]).finish().unwrap(); @@ -1263,7 +1261,6 @@ mod tests { /// max-delay decoder still starts at the group before it, and takes over. #[tokio::test] async fn a_cold_join_whose_live_edge_arrives_first_starts_a_group_earlier() { - kio::clock::host_time(); let (broadcast, mut track) = live_track(); let mut live = group(&mut track, 1, &[4, 5]); @@ -1309,7 +1306,6 @@ mod tests { /// never alternating in between. #[tokio::test] async fn a_short_stall_skips_only_the_min_delay_decoder() { - kio::clock::host_time(); let (broadcast, mut track) = live_track(); let mut consumer = dual( &broadcast, @@ -1337,11 +1333,15 @@ mod tests { // leading by more than a frame, so it is shown at once. let mut live = group(&mut track, 2, &[8]); shown.push(read(&mut consumer).await); + // Mocked time, so the timeout fires only once every task has run, well inside the + // sweep; no decode runs while the max-delay decoder waits on the stalled group. + tokio::time::pause(); assert!( kio::clock::timeout(std::time::Duration::from_millis(100), consumer.next_frame()) .await .is_err() ); + tokio::time::resume(); assert_eq!( consumer.selector.source(), Lane::Min, @@ -1375,7 +1375,6 @@ mod tests { /// late frames are never shown, and the max-delay decoder still takes over. #[tokio::test] async fn a_long_stall_skips_both_decoders() { - kio::clock::host_time(); let (broadcast, mut track) = live_track(); let mut consumer = dual( &broadcast, diff --git a/rs/moq-video/src/encode/producer.rs b/rs/moq-video/src/encode/producer.rs index e9b9b30607a..43361aba97a 100644 --- a/rs/moq-video/src/encode/producer.rs +++ b/rs/moq-video/src/encode/producer.rs @@ -1557,7 +1557,6 @@ mod tests { /// acquisition: not zero, and not the later instant the loop dequeued it. #[tokio::test] async fn a_late_first_frame_publishes_its_acquisition() { - kio::clock::host_time(); tokio::task::LocalSet::new() .run_until(async { let fixture = Fixture::start(Duration::from_secs(5), kio::clock::wall()).await; @@ -1636,7 +1635,6 @@ mod tests { /// broadcast forward with the device's spacing instead of rewinding it. #[tokio::test] async fn a_device_clock_restart_continues_forward() { - kio::clock::host_time(); tokio::task::LocalSet::new() .run_until(async { let fixture = Fixture::start(Duration::from_secs(1), kio::clock::wall()).await; @@ -1680,7 +1678,6 @@ mod tests { /// frame after a resume lands after the idle gap, at its own acquisition. #[tokio::test] async fn a_restart_after_idle_keeps_the_gap() { - kio::clock::host_time(); tokio::task::LocalSet::new() .run_until(async { let idle = Duration::from_millis(300);