diff --git a/swarm-matrix-ctl/src/appservice.rs b/swarm-matrix-ctl/src/appservice.rs index 20b8520b..4f1d6e81 100644 --- a/swarm-matrix-ctl/src/appservice.rs +++ b/swarm-matrix-ctl/src/appservice.rs @@ -447,15 +447,16 @@ mod tests { const REGEX: &str = "^@[a-z0-9._=/-]+:t\\.local$"; + /// A directory of its own per call. A counter, not the clock, keeps two + /// tests that start in the same clock tick out of one directory. fn scratch() -> PathBuf { + static NEXT: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0); let dir = std::env::temp_dir().join(format!( "swarm-appservice-{}-{}", std::process::id(), - std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .expect("after the epoch") - .as_nanos() + NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed) )); + std::fs::remove_dir_all(&dir).ok(); std::fs::create_dir_all(&dir).expect("temp dir"); dir }