Skip to content

Commit cb6bb89

Browse files
karthiknadigCopilot
andcommitted
test: prevent virtualenvwrapper temp directory collisions (Fixes #498)
Combine timestamp, process ID, and an atomic sequence so parallel tests cannot share cleanup paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b618197 commit cb6bb89

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

crates/pet-virtualenvwrapper/src/environments.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,23 @@ mod tests {
5959
use std::{
6060
fs,
6161
path::Path,
62+
sync::atomic::{AtomicUsize, Ordering},
6263
time::{SystemTime, UNIX_EPOCH},
6364
};
6465

6566
#[cfg(windows)]
6667
use std::os::windows::fs::symlink_dir;
6768

69+
static NEXT_TEST_DIR_ID: AtomicUsize = AtomicUsize::new(0);
70+
6871
fn create_test_dir(name: &str) -> PathBuf {
69-
let unique = SystemTime::now()
72+
let id = NEXT_TEST_DIR_ID.fetch_add(1, Ordering::Relaxed);
73+
let timestamp = SystemTime::now()
7074
.duration_since(UNIX_EPOCH)
7175
.unwrap()
7276
.as_nanos();
7377
let directory = std::env::temp_dir().join(format!(
74-
"pet-virtualenvwrapper-{name}-{}-{unique}",
78+
"pet-virtualenvwrapper-{name}-{}-{timestamp}-{id}",
7579
std::process::id()
7680
));
7781
fs::create_dir_all(&directory).unwrap();

0 commit comments

Comments
 (0)