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
19 changes: 0 additions & 19 deletions quest/m0/flaky-looping-media.md

This file was deleted.

23 changes: 23 additions & 0 deletions quest/m0/flaky-media-restart.md
Original file line number Diff line number Diff line change
@@ -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.
46 changes: 27 additions & 19 deletions rs/moq-scene/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down