diff --git a/crates/context/src/critique_storage.rs b/crates/context/src/critique_storage.rs index 95ef0f4ea..7cc88fade 100644 --- a/crates/context/src/critique_storage.rs +++ b/crates/context/src/critique_storage.rs @@ -687,11 +687,17 @@ mod tests_660 { use std::collections::HashMap; use std::path::PathBuf; + static TMP_SEQ: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + fn tmp() -> String { let base = std::env::temp_dir().join(format!( - "impeccable-critique-{}-{}", + "impeccable-critique-{}-{}-{}", std::process::id(), - std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos() + std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos(), + // A per-process counter: Windows' clock is coarse enough that two + // parallel tests can share a nanosecond stamp and then delete each + // other's directories. + TMP_SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed) )); std::fs::create_dir_all(&base).unwrap(); // Like Node's `realpathSync`: no `\\?\` verbatim prefix on Windows, diff --git a/crates/context/src/staleness_deep.rs b/crates/context/src/staleness_deep.rs index 10dfbc772..fb3ea4622 100644 --- a/crates/context/src/staleness_deep.rs +++ b/crates/context/src/staleness_deep.rs @@ -437,11 +437,17 @@ pub fn load_known_rule_ids() -> Option> { mod tests { use super::check_hook_installation; + static TMP_SEQ: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + fn tmp() -> String { let base = std::env::temp_dir().join(format!( - "impeccable-doctor-hook-{}-{}", + "impeccable-doctor-hook-{}-{}-{}", std::process::id(), - std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos() + std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos(), + // A per-process counter: Windows' clock is coarse enough that two + // parallel tests can share a nanosecond stamp and then delete each + // other's directories. + TMP_SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed) )); std::fs::create_dir_all(&base).unwrap(); // Like Node's `realpathSync`: on Windows, `canonicalize` yields a diff --git a/crates/hook/tests/cache_root_tests.rs b/crates/hook/tests/cache_root_tests.rs index eaa8a6ebc..366e0d5bd 100644 --- a/crates/hook/tests/cache_root_tests.rs +++ b/crates/hook/tests/cache_root_tests.rs @@ -47,9 +47,13 @@ struct Tmp(PathBuf); impl Tmp { fn new() -> Tmp { let base = std::env::temp_dir().join(format!( - "impeccable-cache-root-{}-{}", + "impeccable-cache-root-{}-{}-{}", std::process::id(), - std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos() + std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos(), + // A per-process counter: Windows' clock is coarse enough that two + // parallel tests can share a nanosecond stamp and then delete each + // other's directories. + TMP_SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed) )); std::fs::create_dir_all(&base).unwrap(); // Like Node's `realpathSync`: no `\\?\` verbatim prefix on Windows, so the