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:
1 file changed
+8
-1
+8
-1
@@ -2289,10 +2289,17 @@ mod tests {
|
||||
|
||||
impl TempDir {
|
||||
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)
|
||||
.unwrap()
|
||||
.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}"));
|
||||
fs::create_dir_all(&path).unwrap();
|
||||
Self { path }
|
||||
|
||||
Reference in new issue
Block a user