Take the keyframe baseline of the layer-format test after the streamer has settled

stream::tests::layer_formats_reach_the_live_stream asserts that telling the
sink the same layer format twice asks for no second keyframe: it drains the
sink's keyframe requests, changes the format, waits for the request that
follows, tells the same format again and expects none within 200 ms. It failed
once ("nothing changed", stream.rs:1326) in the first of the three final runs of
the CI test step in the runner image of this task, with the machine busy with
another job.

Requests reach the sink from the stream going live, from the streamer's own
view of its viewer connecting (PeerEvent::Connected, a moment after the viewer
sees WatchState::Connected, which is all the test waited for), from the
viewer's picture requests, and from a changed layer. The test drained once,
right after the viewer's side was connected, so a request of one of the first
three that arrives later is taken for the one the changed format asked for, and
the real one then arrives after the "same again" and is counted as a change.
This could not be reproduced here (0 in 400 runs of the single test, 32 at a
time with 48 busy loops, nor in 200 runs of the lib tests); the change closes
those windows as far as they can be named: the test waits for the streamer's
own Connected (StreamViewers) as well, and drains until a moment longer than
the merge interval of requests (250 ms) passes with no request, before the
format is changed. The assertions are those of before.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-24 21:42:15 +03:00
1 parent 272de7a13d
commit 443559aa79
1 file changed
+24 -4
+24 -4
View File
@@ -1295,9 +1295,21 @@ mod tests {
// Before the viewer asks: its offer is made after this.
sink.layer_format(0, format(60_000_000));
handles[1].send(StreamCmd::Watch { stream_id: "s-1".into() });
wait(&mut rx, |e| match e {
Event::WatchState { session: 2, state: WatchState::Connected, .. } => Some(()),
_ => None,
// Connected for the viewer and for the streamer, in either order: the
// streamer asks for a keyframe when its viewer connects, a moment after
// the viewer has seen the connection.
let (mut watching, mut served) = (false, false);
wait(&mut rx, |e| {
match e {
Event::WatchState { session: 2, state: WatchState::Connected, .. } => {
watching = true;
}
Event::StreamViewers { session: 1, viewers } => {
served |= viewers.iter().any(|v| v.state == ViewerState::Connected);
}
_ => {}
}
(watching && served).then_some(())
})
.await;
// 3840x2160 at 60 fps is level 5.2 (0x34) in both profiles.
@@ -1312,7 +1324,15 @@ mod tests {
sink.take_layer_keyframes(&mut layers);
layers.contains(0)
};
keyframes();
// What asked for a keyframe so far (going live, the viewer's connecting
// and its first picture request) is done when a moment longer than the
// merging interval of requests (250 ms) passes with none.
for _ in 0..50 {
tokio::time::sleep(Duration::from_millis(300)).await;
if !keyframes() {
break;
}
}
sink.layer_format(0, format(9_000_000));
timeout(Duration::from_secs(5), async {
while !keyframes() {