From 995c44e714e381c6729217bee0286ea6af573556 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 24 Oct 2026 19:00:18 -0700 Subject: [PATCH] codecs: the rayon deadlock test allows 120 s between two answered frame requests gop::tests::rayon_frame_requests_while_decoding_on_rayon_never_deadlock gave its 3,840 frame requests 120 s in total. On a loaded machine they take longer while every request is still answered. With six copies of the test running at once, all 12 runs on `main` failed after 121 to 123 s with "frame requests deadlocked". The test now counts answered requests and fails when none is answered for 120 s. The same 12 runs pass, in 166 to 259 s. With the #480 fix in `isolated` turned off, the test still fails ("frame requests deadlocked after 927 frames"). --- crates/codecs/src/gop.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/codecs/src/gop.rs b/crates/codecs/src/gop.rs index dcd19a2851..a6b06df985 100644 --- a/crates/codecs/src/gop.rs +++ b/crates/codecs/src/gop.rs @@ -1082,6 +1082,8 @@ mod tests { use rayon::prelude::*; let s = Arc::new(ParSamples(samples(240, 30, 4, false))); let (tx, rx) = std::sync::mpsc::channel(); + let done = Arc::new(AtomicUsize::new(0)); + let counted = done.clone(); std::thread::spawn(move || { for round in 0..40usize { // export-like: many frame workers, frames of several GOPs of a fresh source at once @@ -1089,11 +1091,25 @@ mod tests { (0..96usize).into_par_iter().with_max_len(1).for_each(|k| { let i = (k * 37 + round * 53) % 240; assert_eq!(index_of(&c.frame(&*s, i as i64 * 1000).expect("frame")), i); + counted.fetch_add(1, Ordering::Relaxed); }); } let _ = tx.send(()); }); - assert!(rx.recv_timeout(Duration::from_secs(120)).is_ok(), "frame requests deadlocked"); + // A deadlock stops every request of a round for good. On a loaded machine the 3,840 + // requests can take minutes, so the limit applies to the time between two answered ones. + let mut answered = 0; + loop { + match rx.recv_timeout(Duration::from_secs(120)) { + Ok(()) => break, + Err(std::sync::mpsc::RecvTimeoutError::Timeout) => { + let now = done.load(Ordering::Relaxed); + assert!(now > answered, "frame requests deadlocked after {now} frames"); + answered = now; + } + Err(std::sync::mpsc::RecvTimeoutError::Disconnected) => panic!("a frame request failed"), + } + } } #[test]