From 399ec3b813f01d73a28dcd56ecb481a8bad783c3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 10:07:40 -0800 Subject: [PATCH 1/3] chore(quest): claim quest/m0/flaky-looping-media.md Quest-Claim: f7e41f36a412c80e From 3f8e6f644c0e3970bba50600ff409f7d7eb71b6b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 10:41:47 -0800 Subject: [PATCH 2/3] test(scene): the looping media test waits for each picture under load The test jumped a paused clock to 950 ms in one sleep. Pictures decode on moq-video's own thread, which tokio cannot see, so while the runtime sat idle the clock ran past 800 and 900 ms before those pictures existed, and the slot still held 700 or 800 ms. Step the clock to one picture's moment at a time and wait for it there, as the play-once test already did, through a helper both share; then read the loop's start at its end, before the second play's next picture can replace it. Co-Authored-By: Claude Opus 5.5 --- quest/m0/flaky-looping-media.md | 19 ------------------ rs/moq-scene/src/source.rs | 34 ++++++++++++++++++++------------- 2 files changed, 21 insertions(+), 32 deletions(-) delete mode 100644 quest/m0/flaky-looping-media.md diff --git a/quest/m0/flaky-looping-media.md b/quest/m0/flaky-looping-media.md deleted file mode 100644 index 377f1d20..00000000 --- a/quest/m0/flaky-looping-media.md +++ /dev/null @@ -1,19 +0,0 @@ -# [S] The looping media test holds under load - -## Goal - -`source::media_tests::a_looping_media_file_starts_over` passes however busy -the host is. - -## Plan - -Seen once in a full `just test` on a shared host (moq-dev/studio#172): -the picture shown at 950 ms on the paused clock was the 700 ms frame, not the -900 ms one (`rs/moq-scene/src/source.rs`, the `Duration::from_millis(900)` -assertion). Four reruns of the media tests alone and one full run passed. -The test pauses tokio's clock, which auto-advances whenever the runtime is -idle, while the file decodes on a thread of its own, so under load the clock -can run past frames the decoder has not delivered yet. Reproduce it under CPU -load first, such as with `stress-ng` beside the test, then make the test wait -on the decoder rather than on the clock, or have the clock wait for the -decoder in the source itself if a real run can show the same skip. diff --git a/rs/moq-scene/src/source.rs b/rs/moq-scene/src/source.rs index 1aaa3e30..a03428b8 100644 --- a/rs/moq-scene/src/source.rs +++ b/rs/moq-scene/src/source.rs @@ -3965,6 +3965,23 @@ mod media_tests { } } + /// Check that the clip's pictures after `first`, which showed at `begin`, + /// each show at its moment and not before, stepping the clock to one moment + /// at a time. Each step waits for its picture: pictures decode on a thread + /// tokio cannot see, so a clock moved past several moments at once runs on + /// ahead of the ones not decoded yet, which then show late. + async fn plays_on_time(feed: &Feed, first: moq_net::Timestamp, begin: Instant) { + for index in 1..10u64 { + let into = Duration::from_millis(index * 100); + // Within the timer wheel's millisecond of when the test saw the first. + until_time(begin.saturating_add(into).saturating_sub(Duration::from_millis(2))).await; + assert!(feed.next_picture().is_none(), "picture {index} before its moment"); + until_time(begin.saturating_add(into)).await; + let (timestamp, _) = shown(feed).await; + assert_eq!(Duration::from(timestamp) - Duration::from(first), into); + } + } + /// Wait until `name` reads as `status`, without moving the clock. async fn until_status(sources: &Sources, name: &str, status: Status) { until(|| (sources.get(name).unwrap().status() == status).then_some(())).await; @@ -3986,15 +4003,7 @@ mod media_tests { let (first, begin) = shown(feed).await; assert_eq!(feed.status(), Status::Live); - for index in 1..10u64 { - let into = Duration::from_millis(index * 100); - // Within the timer wheel's millisecond of when the test saw the first. - until_time(begin.saturating_add(into).saturating_sub(Duration::from_millis(2))).await; - assert!(feed.next_picture().is_none(), "picture {index} before its moment"); - until_time(begin.saturating_add(into)).await; - let (timestamp, _) = shown(feed).await; - assert_eq!(Duration::from(timestamp) - Duration::from(first), into); - } + plays_on_time(feed, first, begin).await; // The last picture lasts as long as the one before it, and the // sound runs a little past it. @@ -4174,12 +4183,11 @@ mod media_tests { let feed = sources.get("clip.mkv").unwrap(); let (first, begin) = shown(feed).await; - until_time(begin.saturating_add(Duration::from_millis(950))).await; - let (last, _) = shown(feed).await; - assert_eq!(Duration::from(last) - Duration::from(first), Duration::from_millis(900)); + plays_on_time(feed, first, begin).await; until_time(begin.saturating_add(Duration::from_millis(998))).await; assert!(feed.next_picture().is_none(), "the start again before the end"); - until_time(begin.saturating_add(Duration::from_millis(1_100))).await; + // At the end, before the second play's next picture is due. + until_time(begin.saturating_add(Duration::from_millis(1_000))).await; let (again, _) = shown(feed).await; assert_eq!(again, first); assert_eq!(feed.status(), Status::Live); From 142af2c057a646621f627ccd95b08ae074a9f899 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 14:08:48 -0800 Subject: [PATCH 3/3] test(scene): the loop's second play is read where the first ended The second play begins at the first one's end, which its sound puts a little past 1 s, so holding the clock at 1 s waited forever. Read the end from the feed's run instead. Adds a follow-up quest for the restart test, which hung once under the same load. Co-Authored-By: Claude Opus 5.5 --- quest/m0/flaky-media-restart.md | 23 +++++++++++++++++++++++ rs/moq-scene/src/source.rs | 7 +++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 quest/m0/flaky-media-restart.md diff --git a/quest/m0/flaky-media-restart.md b/quest/m0/flaky-media-restart.md new file mode 100644 index 00000000..48ddfeb6 --- /dev/null +++ b/quest/m0/flaky-media-restart.md @@ -0,0 +1,23 @@ +# [S] The media restart test holds under load + +## Goal + +`source::media_tests::a_media_file_restarts_going_on_program` passes however +busy the host is. + +## Plan + +It hung once in 60 runs of `source::media_tests::` beside `stress-ng --cpu 96` +on a 32-CPU host, while the other eleven media tests passed every run +(found by moq-dev/studio#181, which fixed the looping test's flake under the +same load). A hang under a paused clock means the test holds the clock, with +`until`'s zero sleep, short of a moment the source sleeps until. + +Reproduce it first as #181 did: the test binary run 200 times, 16 at a time, +beside `stress-ng`, each under `timeout 120`. Then find which wait holds. One lead: the comment before the +first `until_time` says waiting for both clips "while the clock holds" starts +them together, but `shown` moves the clock to the intro's start with +`until_time`, so the still clip can begin later, and the fixed 1.1 s may not +cover both plays' ends, which include sound running past the last picture. +Read each play's end from `Feed::run().ended` instead of a fixed offset, as +#181 does for the loop. diff --git a/rs/moq-scene/src/source.rs b/rs/moq-scene/src/source.rs index a03428b8..8dcee5a2 100644 --- a/rs/moq-scene/src/source.rs +++ b/rs/moq-scene/src/source.rs @@ -4186,8 +4186,11 @@ mod media_tests { plays_on_time(feed, first, begin).await; until_time(begin.saturating_add(Duration::from_millis(998))).await; assert!(feed.next_picture().is_none(), "the start again before the end"); - // At the end, before the second play's next picture is due. - until_time(begin.saturating_add(Duration::from_millis(1_000))).await; + // The second play begins where the first ended, its sound a little + // past its last picture; holding the clock there keeps the second + // play's next picture from replacing its first. + let end = until(|| feed.run().ended).await; + until_time(end).await; let (again, _) = shown(feed).await; assert_eq!(again, first); assert_eq!(feed.status(), Status::Live);