From 0cc92cea36c3d86c595917c0955757efc46cb5ef Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 17 Nov 2026 09:33:55 -0800 Subject: [PATCH] test(moq-cli): a killed recording is cut once it holds a fragment of each track The import no longer holds its catalog for the two-second mux-rate window, so the export starts with the first media and 10 KB of audio fragments land before the first video GOP closes. Wait for a complete fragment of both tracks instead of a byte count. Co-Authored-By: Claude Opus 5.5 --- rs/moq-cli/tests/integration/export.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/rs/moq-cli/tests/integration/export.rs b/rs/moq-cli/tests/integration/export.rs index 464dc59520f..6f4f64aedb9 100644 --- a/rs/moq-cli/tests/integration/export.rs +++ b/rs/moq-cli/tests/integration/export.rs @@ -1172,13 +1172,14 @@ async fn a_killed_mp4_recording_is_repaired() { .expect("spawn export"); let (mut publisher, feeding) = import(&relay); + // Audio fragments as its groups end, video only at the next keyframe, two seconds in. kio::clock::timeout(TIMEOUT, async { - while std::fs::metadata(&path).map_or(0, |file| file.len()) < 10_000 { + while fragmented(&std::fs::read(&path).unwrap_or_default()).len() < 2 { kio::clock::sleep(Duration::from_millis(50)).await; } }) .await - .expect("the recording never grew"); + .expect("the recording never held a fragment of each track"); // The recorder holds its lock while it writes, so repairing now would corrupt the file. let mid = std::fs::read(&path).unwrap(); let refused = moq_repair(&path).await; @@ -1235,6 +1236,18 @@ fn boxes(file: &[u8]) -> Vec { boxes } +/// The track ids with a complete moof+mdat fragment in a recording, possibly mid-write. +fn fragmented(file: &[u8]) -> std::collections::HashSet { + boxes(file) + .windows(2) + .filter_map(|pair| match pair { + [mp4_atom::Any::Moof(moof), mp4_atom::Any::Mdat(_)] => Some(moof), + _ => None, + }) + .flat_map(|moof| moof.traf.iter().map(|traf| traf.tfhd.track_id)) + .collect() +} + /// Count the frames the relay delivers on `demo`'s video track as they arrive. A GOP lasts two /// seconds, so subscribing during the first one counts them all. fn delivered(relay: &Relay) -> Arc {