Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 0 additions & 26 deletions quest/m1/listen-admission-test.md

This file was deleted.

150 changes: 150 additions & 0 deletions rs/moq-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<anyhow::Result<()>>,
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::<url::Url>().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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Isolate virtual time from the socket-backed deadline test

When loopback setup or CI scheduling is slow, this pauses Tokio only after server accept has already created the one-second deadline and admissions.next() has returned, so more than 500 ms spent before the pause makes the subsequent 500 ms advance legitimately expire the deadline and fail a correct implementation. The second test has the same sensitivity after resuming with only one second left for the server task to consume the grant. Keep the TCP-backed path on wall-clock time with lower-bound assertions, or move the virtual-time deadline checks behind a socket-free harness.

AGENTS.md reference: rs/AGENTS.md:L51-L54

Useful? React with 👍 / 👎.

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
Expand Down
Loading