M8: save-format tests keep their temp folders apart

SaveFiles named each test's folder after the process id and the
clock in nanoseconds. The tests run in parallel and the macOS clock
counts microseconds, so two of them often got the same folder and one
failed with AlreadyExists (14 of 30 runs here). A counter now keeps
the names apart.
This commit is contained in:
MortenHusted committed 2026-10-22 09:37:35 +02:00
1 parent a86897dc91
commit 0449edf645
1 file changed
+5 -1
+5 -1
View File
@@ -15,8 +15,12 @@ struct SaveFiles {
impl SaveFiles {
fn new() -> Self {
// Tests run in parallel and the clock can read the same for two of them (macOS counts
// microseconds), so a counter keeps their folders apart.
static NEXT: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
let n = NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
let stamp = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos();
let dir = std::env::temp_dir().join(format!("figcraft-save-formats-{}-{stamp}", std::process::id()));
let dir = std::env::temp_dir().join(format!("figcraft-save-formats-{}-{stamp}-{n}", std::process::id()));
std::fs::create_dir(&dir).unwrap();
Self { dir, files: Vec::new() }
}