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/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 65c8fbbd..e26c31e5 100644 --- a/rs/moq-scene/src/source.rs +++ b/rs/moq-scene/src/source.rs @@ -3984,6 +3984,26 @@ 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::try_from(timestamp).unwrap() - Duration::try_from(first).unwrap(), + 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; @@ -4005,18 +4025,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::try_from(timestamp).unwrap() - Duration::try_from(first).unwrap(), - 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. @@ -4196,15 +4205,14 @@ 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::try_from(last).unwrap() - Duration::try_from(first).unwrap(), - 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; + // 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);