Tests: make the temp-dir helpers unique under a coarse clock

Windows' system clock is coarse enough that two parallel tests could get
the same pid-plus-nanoseconds directory name and then remove each
other's files (rust-windows: close_verb_round_trip_and_ownership,
NotFound). A per-process counter is appended to the name.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vau2X53xGTjjTCXWMVBoNY
This commit is contained in:
Paul Bakaus
2026-09-04 10:32:53 -07:00
co-authored by Claude Code
parent 45ad3c49e5
commit 6099995338
3 changed files with 22 additions and 6 deletions
+8 -2
View File
@@ -687,11 +687,17 @@ mod tests_660 {
use std::collections::HashMap;
use std::path::PathBuf;
static TMP_SEQ: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
fn tmp() -> String {
let base = std::env::temp_dir().join(format!(
"impeccable-critique-{}-{}",
"impeccable-critique-{}-{}-{}",
std::process::id(),
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos()
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos(),
// A per-process counter: Windows' clock is coarse enough that two
// parallel tests can share a nanosecond stamp and then delete each
// other's directories.
TMP_SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
));
std::fs::create_dir_all(&base).unwrap();
// Like Node's `realpathSync`: no `\\?\` verbatim prefix on Windows,
+8 -2
View File
@@ -437,11 +437,17 @@ pub fn load_known_rule_ids() -> Option<Vec<String>> {
mod tests {
use super::check_hook_installation;
static TMP_SEQ: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
fn tmp() -> String {
let base = std::env::temp_dir().join(format!(
"impeccable-doctor-hook-{}-{}",
"impeccable-doctor-hook-{}-{}-{}",
std::process::id(),
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos()
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos(),
// A per-process counter: Windows' clock is coarse enough that two
// parallel tests can share a nanosecond stamp and then delete each
// other's directories.
TMP_SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
));
std::fs::create_dir_all(&base).unwrap();
// Like Node's `realpathSync`: on Windows, `canonicalize` yields a
+6 -2
View File
@@ -47,9 +47,13 @@ struct Tmp(PathBuf);
impl Tmp {
fn new() -> Tmp {
let base = std::env::temp_dir().join(format!(
"impeccable-cache-root-{}-{}",
"impeccable-cache-root-{}-{}-{}",
std::process::id(),
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos()
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos(),
// A per-process counter: Windows' clock is coarse enough that two
// parallel tests can share a nanosecond stamp and then delete each
// other's directories.
TMP_SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
));
std::fs::create_dir_all(&base).unwrap();
// Like Node's `realpathSync`: no `\\?\` verbatim prefix on Windows, so the