diff --git a/quest/m1/README.md b/quest/m1/README.md index afa3bbc9974..1d1b5a56557 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -99,7 +99,6 @@ lite-07 stream type here. - [Audio jitter target](/quest/m1/audio-jitter-target/README.md) - the playout target is default in both languages; a manual browser proof and a native trace replay remain - [A/V clock](/quest/m1/av-clock.md) - the audio playhead drives Sync.reference while audio plays, through per-track sync handles - [Publish channel count](/quest/m1/publish-audio-channel-count.md) - forcing a channel count on an Audio.Capture stops costing the subscriber gaps of silence, and the media fixture's cold-start audio-tone flake is fixed at its cause -- [moq --listen admission test](/quest/m1/listen-admission-test.md) - an in-process test proves `moq --listen` bounds admission by `listen.timeout` - [Container reads drop backfill](/quest/m1/read-backfill.md) - the JS container consumer drops groups below its read cursor like Rust - [qmux no-wait opens](/quest/m1/qmux-no-wait.md) - the in-tree @moq/qmux rejects an over-limit create when waitUntilAvailable is false, like Chrome - [TS fidelity and recovery](/quest/m1/ts-reliability/README.md) - both modes have explicit profiles, automated validation, loss tests, and a dedicated guide diff --git a/quest/m1/listen-admission-test.md b/quest/m1/listen-admission-test.md deleted file mode 100644 index 20c3f1d6f37..00000000000 --- a/quest/m1/listen-admission-test.md +++ /dev/null @@ -1,26 +0,0 @@ -# [XS] Test that moq --listen bounds admission - -## Goal - -An in-process test proves that `moq --listen` bounds auth admission by -`listen.timeout`: an admission that never answers closes at the deadline, one -answered just inside it is admitted, and `"0"` waits. Today -`rs/moq-cli/tests/listen.rs` drives the binary with `--auth-public`, where -admission never waits, so nothing covers `serve_client` -(`rs/moq-cli/src/main.rs`) running admission under the handshake deadline. - -## Plan - -Decided with the maintainer on 2026-10-20, from the follow-ups of -[#5765](https://github.com/moq-dev/moq/pull/5765), which landed the -deadline. - -- Drive `moq --listen`'s listener in process on controlled time, through the - path that runs admission under the handshake deadline (#5765's - `Request::within`), with an auth decider that can stall, rather than the - binary on wall time. Calling `serve_client` alone would leave the deadline - out. If the listener cannot be driven that way, open the smallest seam that - lets it. -- Match the relay's `auth_lifetime` cases so the two listeners stay alike. - -Public API: none. Wire: none. diff --git a/rs/moq-cli/src/main.rs b/rs/moq-cli/src/main.rs index cec55f97455..e39ff2b876d 100644 --- a/rs/moq-cli/src/main.rs +++ b/rs/moq-cli/src/main.rs @@ -1122,6 +1122,156 @@ mod tests { assert_eq!(reason, moq_auth::lease::Reason::Shutdown); } + mod listen_admission { + use super::*; + use futures::FutureExt; + use std::time::Duration; + + const TIMEOUT: Duration = Duration::from_secs(10); + + struct Listening { + tasks: JoinSet>, + admissions: moq_relay::auth::Admissions, + connection: moq_tokio::Connection, + consumer: moq_net::origin::Consumer, + _shutdown: Shutdown, + _broadcast: moq_net::broadcast::Producer, + _track: moq_net::track::Producer, + } + + impl Listening { + async fn new(timeout: &str) -> Self { + let _ = moq_tokio::crypto::install_default(); + let cli = Invocation::try_parse_from([ + "moq", + "--listen-tcp-bind", + "127.0.0.1:0", + "--listen-timeout", + timeout, + "import", + "ts", + ]) + .unwrap(); + let listener = cli.moq.server_config().init_streams().unwrap().listen().await.unwrap(); + let addr = listener.tcp_local_addr().unwrap(); + let cluster = moq_relay::cluster::Cluster::new(Default::default()).unwrap(); + let broadcast = cluster.origin.create_broadcast("probe").unwrap(); + broadcast.announce(Default::default()).unwrap(); + let info = moq_net::track::Info::default().with_timescale(moq_net::Timescale::MILLI); + let track = broadcast.create_track("status", info).unwrap(); + let mut group = track.append_group().unwrap(); + group + .write_frame(moq_net::Timestamp::ZERO, b"admitted".as_ref()) + .unwrap(); + group.finish().unwrap(); + let (auth, admissions) = moq_relay::auth::Auth::embedded("test-cli"); + let (trigger, observer) = moq_relay::shutdown::Observer::new(TIMEOUT); + let serving = Serving { + cluster, + auth, + directions: Directions { + publish: true, + consume: false, + }, + shutdown: observer.clone(), + lan: false, + public_quic: false, + }; + let mut tasks = JoinSet::new(); + spawn_serve(&mut tasks, listener, serving); + let origin = moq_tokio::origin::spawn(); + let consumer = origin.consume(); + let mut client = moq_tokio::connect::Config::default(); + // Only the listener's deadline may end the undecided admission. + client.timeout = Some(Duration::ZERO); + let client = client + .init(Default::default()) + .unwrap() + .with_subscriber(origin) + .with_reconnect(false); + let connection = client.connect(format!("tcp://{addr}/").parse::().unwrap()); + Self { + tasks, + admissions, + connection, + consumer, + _shutdown: Shutdown { trigger, observer }, + _broadcast: broadcast, + _track: track, + } + } + } + + #[tokio::test] + async fn an_unanswered_admission_closes_at_the_listen_deadline() { + let mut listening = Listening::new("1s").await; + let admission = listening.admissions.next().await.unwrap(); + // Loopback establishes the request first; only admission runs on controlled time. + tokio::time::pause(); + tokio::time::advance(Duration::from_millis(500)).await; + assert!( + listening.connection.closed().now_or_never().is_none(), + "admission ended before its deadline" + ); + tokio::time::advance(Duration::from_secs(1)).await; + tokio::time::resume(); + let error = tokio::time::timeout(TIMEOUT, listening.connection.closed()) + .await + .unwrap() + .unwrap_err(); + assert!( + matches!(&error, moq_tokio::Error::MoqNet(error) if moq_net::SessionError::from(error) == moq_net::SessionError::Timeout), + "expected the listener's timeout close, got {error:?}" + ); + drop(admission); + listening.tasks.shutdown().await; + } + + #[tokio::test] + async fn a_late_admission_within_the_deadline_or_with_zero_timeout_serves() { + for timeout in ["12s", "0"] { + let mut listening = Listening::new(timeout).await; + let admission = listening.admissions.next().await.unwrap(); + tokio::time::pause(); + // Past the former ten-second admission cap, but inside the listener's bound. + tokio::time::advance(Duration::from_secs(11)).await; + // Poll already-woken deadlines before making the decision ready. + tokio::task::yield_now().await; + assert!( + listening.connection.closed().now_or_never().is_none(), + "{timeout}: decided before the grant" + ); + admission.grant(moq_auth::lease::Consumer::fixed(moq_auth::Grant::new( + moq_auth::Pattern::all(), + moq_auth::Pattern::all(), + ))); + tokio::time::resume(); + let connection = tokio::time::timeout(TIMEOUT, listening.connection.clone().established()) + .await + .unwrap() + .unwrap(); + // Media proves the CLI admitted the session, even on a transport that establishes early. + let payload = tokio::time::timeout(TIMEOUT, async { + let broadcast = listening.consumer.routed_broadcast("probe").await.unwrap(); + let mut track = broadcast + .track("status") + .unwrap() + .subscribe(None) + .await + .unwrap() + .ordered(); + let mut group = track.next_group().await.unwrap().unwrap(); + group.read_frame().await.unwrap().unwrap().payload + }) + .await + .unwrap(); + assert_eq!(&payload[..], b"admitted", "{timeout}: grant did not serve the media"); + connection.close().await.unwrap(); + listening.tasks.shutdown().await; + } + } + } + /// A local pipeline that dies takes the process with it, even while another one is /// still running. Reporting completion from inside the task instead would miss /// this: a panic skips the report, leaving the survivor to keep the process alive