Skip to content

Commit 959144d

Browse files
committed
fix(test): make gitops temp repo dir unique to avoid macOS parallel-init race
Two parallel tests in this process derived the temp dir from pid+nanos only. macOS clock resolution is coarse, so both could compute the same nanos and share one directory; the second `git init` then failed with "cannot copy template ... .git/info/exclude: File exists". Append a per-call atomic counter so each repo gets a unique path regardless of timing. Fixes the flaky macOS CI failure in gitops::clear_cache_removes_dir. # ── git-warden policy guide ── # Write the commit message in English # AI co-author trailers will be removed before commit
1 parent 6bd8dc1 commit 959144d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

tests/gitops.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@ fn git(dir: &Path, args: &[&str]) {
2424
}
2525

2626
fn temp_repo() -> std::path::PathBuf {
27+
use std::sync::atomic::{AtomicU64, Ordering};
28+
// A per-call atomic counter guarantees a unique directory even when two parallel
29+
// tests in this process compute the same timestamp (macOS clock resolution is coarse,
30+
// so `as_nanos()` can collide). Without it, both share one dir and the second
31+
// `git init` fails copying templates onto the first's `.git/info/exclude`.
32+
static COUNTER: AtomicU64 = AtomicU64::new(0);
2733
let nanos = std::time::SystemTime::now()
2834
.duration_since(std::time::UNIX_EPOCH)
2935
.unwrap()
3036
.as_nanos();
31-
let dir = std::env::temp_dir().join(format!("gv-gitops-{}-{nanos}", std::process::id()));
37+
let seq = COUNTER.fetch_add(1, Ordering::Relaxed);
38+
let dir = std::env::temp_dir().join(format!("gv-gitops-{}-{nanos}-{seq}", std::process::id()));
3239
std::fs::create_dir_all(&dir).unwrap();
3340
git(&dir, &["init", "-q", "-b", "main"]);
3441
git(&dir, &["config", "commit.gpgsign", "false"]);

0 commit comments

Comments
 (0)