test: use collision-proof temp dirs in macro_policy tests
The with_macro_dirs fixture derived its temp-dir name from a wall-clock nanosecond timestamp, so parallel tests starting in the same clock tick shared a directory and saw each other's macro files (flaky on CI runners with coarse tick granularity). A process id + atomic counter makes the name unique by construction.
This commit is contained in:
@@ -290,7 +290,8 @@ mod tests {
|
|||||||
use crate::utils::get_env_name;
|
use crate::utils::get_env_name;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{env, fs, time};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
use std::{env, fs, process};
|
||||||
|
|
||||||
fn valid_macro() -> Macro {
|
fn valid_macro() -> Macro {
|
||||||
Macro {
|
Macro {
|
||||||
@@ -748,10 +749,12 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn with_macro_dirs<F: FnOnce(&Path, &Path)>(f: F) {
|
fn with_macro_dirs<F: FnOnce(&Path, &Path)>(f: F) {
|
||||||
let unique = time::SystemTime::now()
|
static COUNTER: AtomicUsize = AtomicUsize::new(0);
|
||||||
.duration_since(time::UNIX_EPOCH)
|
let unique = format!(
|
||||||
.unwrap()
|
"{}-{}",
|
||||||
.as_nanos();
|
process::id(),
|
||||||
|
COUNTER.fetch_add(1, Ordering::Relaxed)
|
||||||
|
);
|
||||||
let root = env::temp_dir().join(format!("coyote-macro-policy-test-{unique}"));
|
let root = env::temp_dir().join(format!("coyote-macro-policy-test-{unique}"));
|
||||||
let workspace = root.join("workspace-macros");
|
let workspace = root.join("workspace-macros");
|
||||||
let global = root.join("global-macros");
|
let global = root.join("global-macros");
|
||||||
|
|||||||
Reference in New Issue
Block a user