fix: use atomic counter for temp paths in journal tests
On Windows, SystemTime::now().as_nanos() has ~15ms resolution, causing parallel tests to generate identical file paths and corrupt each other's data.
This commit is contained in:
@@ -10,13 +10,14 @@ use optimizer::storage::{JournalStorage, Storage};
|
||||
use optimizer::{Direction, Study};
|
||||
|
||||
fn temp_path() -> std::path::PathBuf {
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
static COUNTER: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
let mut path = std::env::temp_dir();
|
||||
path.push(format!(
|
||||
"optimizer_journal_test_{}.jsonl",
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos()
|
||||
"optimizer_journal_test_{}_{}.jsonl",
|
||||
std::process::id(),
|
||||
COUNTER.fetch_add(1, Ordering::Relaxed)
|
||||
));
|
||||
path
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user