From 994473adf78e61df70654d847f556575e72c7580 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 15 Sep 2026 15:06:21 +0200 Subject: [PATCH] Fixed the image tests working on the same temporary file --- runtime/src/image.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/runtime/src/image.rs b/runtime/src/image.rs index 23d3e344..78439d67 100644 --- a/runtime/src/image.rs +++ b/runtime/src/image.rs @@ -222,12 +222,21 @@ fn encode(image: &DynamicImage, format: ImageFormat) -> Result, (StatusC mod tests { use super::*; + /// A path no other test works on. + /// + /// The name is counted rather than timed. The clock looks unique but is not: these tests run + /// in parallel, and two of them reading it within the same tick got the same path, so one + /// removed the file the other was still working on. That failed about one run in twelve, and + /// never when the tests ran one after another. fn temporary_image_path(extension: &str) -> std::path::PathBuf { - let unique = std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .unwrap() - .as_nanos(); - std::env::temp_dir().join(format!("mwai-visual-briefing-test-{unique}.{extension}")) + use std::sync::atomic::{AtomicU32, Ordering}; + + // + // The process id is part of it as well, so that two test runs at once stay apart. + // + static NEXT_IMAGE: AtomicU32 = AtomicU32::new(0); + let unique = NEXT_IMAGE.fetch_add(1, Ordering::Relaxed); + std::env::temp_dir().join(format!("mwai-visual-briefing-test-{}-{unique}.{extension}", std::process::id())) } #[test]