mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-18 05:37:59 +00:00
Fixed the image tests working on the same temporary file
This commit is contained in:
1 file changed
+14
-5
+14
-5
@@ -222,12 +222,21 @@ fn encode(image: &DynamicImage, format: ImageFormat) -> Result<Vec<u8>, (StatusC
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
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 {
|
fn temporary_image_path(extension: &str) -> std::path::PathBuf {
|
||||||
let unique = std::time::SystemTime::now()
|
use std::sync::atomic::{AtomicU32, Ordering};
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
|
||||||
.unwrap()
|
//
|
||||||
.as_nanos();
|
// The process id is part of it as well, so that two test runs at once stay apart.
|
||||||
std::env::temp_dir().join(format!("mwai-visual-briefing-test-{unique}.{extension}"))
|
//
|
||||||
|
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]
|
#[test]
|
||||||
|
|||||||
Reference in new issue
Block a user