diff --git a/crates/media/src/exr_planes.rs b/crates/media/src/exr_planes.rs index bed9a38e4..c8c41befd 100644 --- a/crates/media/src/exr_planes.rs +++ b/crates/media/src/exr_planes.rs @@ -371,12 +371,15 @@ pub(crate) fn decodes_of(path: &str) -> Vec { DECODES.lock().unwrap_or_else(PoisonError::into_inner).iter().filter(|(p, _)| p == path).map(|(_, d)| d.clone()).collect() } -/// Run before a decode of a path is queued on the decode threads (`QUEUING`) and when the -/// queued job begins (`STARTING`), keyed by path (tests: holding a decode queued). +/// Run before a decode of a path is queued on the decode threads (`QUEUING`), when the +/// queued job begins (`STARTING`) and after it sent its outcome (`SENT`), keyed by path (tests: +/// holding a decode queued, or its decode thread busy after it). #[cfg(test)] pub(crate) static QUEUING: Mutex> = Mutex::new(Vec::new()); #[cfg(test)] pub(crate) static STARTING: Mutex> = Mutex::new(Vec::new()); +#[cfg(test)] +pub(crate) static SENT: Mutex> = Mutex::new(Vec::new()); #[cfg(test)] fn run_hook(hooks: &Mutex>, path: &str) { @@ -761,7 +764,14 @@ fn run(path: &str, source: &ExrSource, flight: &Arc, base: Option = write(vec![part(None, &RGBA, (32, 32), Compression::ZIP1)], (32, 32)).into(); + let one = 4 * (32 * 32 * 4 + 1); + let store = PlaneStore::new(2 * one); + let all = Want { all: true, ids: Default::default() }; + let get = |p: &str| { + let source = ExrSource::Bytes(bytes.clone()); + let index = crate::exr_index::get(p, &source).unwrap(); + store.get(p, &source, &index, &all, Use::Other).map(|_| ()) + }; + let (a, b, c) = ("/3271-late-a.exr", "/3271-late-b.exr", "/3271-late-c.exr"); + // b's decode thread stays in its job (at most 10 s) after it sent the planes. + let (go, wait) = std::sync::mpsc::channel::<()>(); + let wait = std::sync::Mutex::new(wait); + SENT.lock().unwrap().push(( + b.to_string(), + Arc::new(move |_: &str| { + let _ = wait.lock().unwrap().recv_timeout(std::time::Duration::from_secs(10)); + }), + )); + get(a).unwrap(); + get(b).unwrap(); + get(a).unwrap(); + get(c).unwrap(); + let cached = store.cached(); + let _ = go.send(()); + SENT.lock().unwrap().retain(|(p, _)| p != b); + assert_eq!(cached, [a, c], "b was least recently used"); +} + /// #474 / #3191: a file forgotten (Reload Footage) while it decodes keeps nothing of that decode, /// and the request asks again: no planes made before the reload are kept or served. #[test]