From f508e5bec4270fc58fbc2b9c9f42798c0e560122 Mon Sep 17 00:00:00 2001 From: faumaray Date: Sun, 25 Oct 2026 03:59:07 +0300 Subject: [PATCH] Count frames, not a pause, in the automatic-bitrate test's "not per frame" check Beyond the list of this round, found by its final whole-binary run: 1 of 150 runs of the voelin-core lib beside 32 busy loops failed in an_automatic_bitrate_follows_the_stream, at the assertion that the sink is told the layer's format once per change and not per frame (`left: 2, right: 1`), and the unchanged test failed 2 of 900 runs of its own beside the same load. The sink is told twice for the first picture, and the test counted in between: Streamer::attach tells it the format from the size captured so far (when a frame has been captured before the attach), and the encoder tells it again before its first frame, because its record of what it told starts empty. The test waited for the format, took the count, slept 200 ms and compared; on a busy machine the encoder's first frame comes later than the 200 ms. The test now waits until a frame has been handed over (the encoder tells before it hands over, so both tellings are done), takes the count, waits for five more frames, and compares: "per frame" is counted in frames. The deadline of 30 s only ends a hang. 0 failures of 600 runs of the test beside 32 busy loops. Co-Authored-By: Claude Sonnet 5.5 --- crates/voelin-core/src/media.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/voelin-core/src/media.rs b/crates/voelin-core/src/media.rs index 045f3cf..3d7c322 100644 --- a/crates/voelin-core/src/media.rs +++ b/crates/voelin-core/src/media.rs @@ -3548,10 +3548,24 @@ mod tests { }; told(30).await; assert_eq!(streamer.bitrate_kbps(), 1105); - // Not per frame. - let count = lock(&sink.formats).len(); - tokio::time::sleep(Duration::from_millis(200)).await; - assert_eq!(lock(&sink.formats).len(), count); + // Not per frame. The sink is told when it is attached and again by the + // encoder before its first frame (the same format twice), so the count is + // taken once a frame has been handed over and compared after more have; + // the frames, not a pause, are what "per frame" counts. + let frames_by = |frames: u64| { + let streamer = &streamer; + async move { + let deadline = Instant::now() + Duration::from_secs(30); + while streamer.stats().layers[0].frames < frames { + assert!(Instant::now() < deadline, "{frames} frames: {:?}", streamer.stats()); + tokio::time::sleep(Duration::from_millis(20)).await; + } + } + }; + frames_by(1).await; + let (count, seen) = (lock(&sink.formats).len(), streamer.stats().layers[0].frames); + frames_by(seen + 5).await; + assert_eq!(lock(&sink.formats).len(), count, "told again within five frames"); // The stats follow the sink's being told, not the other way round. let deadline = Instant::now() + Duration::from_secs(10); while streamer.stats().layers[0].bitrate != auto_bitrate(640, 480, 30) {