test(rag): make TempDir names unique across parallel tests

SystemTime nanos alone collide on coarse clocks, so concurrent tests shared
a scratch dir and read each other's generated sbx mixins (flaky
generated_sbx_mixin_* failures in CI).
This commit is contained in:
Dark-Alex-17 committed 2026-09-14 11:13:34 -06:00
1 parent 85cb7b0fbf
commit cee5cf0f36
1 file changed
+8 -1
+8 -1
View File
@@ -2289,10 +2289,17 @@ mod tests {
impl TempDir { impl TempDir {
fn new(tag: &str) -> Self { fn new(tag: &str) -> Self {
let unique = SystemTime::now() // Wall-clock nanos alone are not unique across parallel tests
// (coarse clocks hand the same tick to concurrent callers, so two
// tests would share a directory and overwrite each other's files);
// a process-wide counter makes every name distinct.
static SEQ: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
let nanos = SystemTime::now()
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)
.unwrap() .unwrap()
.as_nanos(); .as_nanos();
let seq = SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
let unique = format!("{nanos}-{seq}");
let path = env::temp_dir().join(format!("coyote-rag-{tag}-{unique}")); let path = env::temp_dir().join(format!("coyote-rag-{tag}-{unique}"));
fs::create_dir_all(&path).unwrap(); fs::create_dir_all(&path).unwrap();
Self { path } Self { path }