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};
|
use optimizer::{Direction, Study};
|
||||||
|
|
||||||
fn temp_path() -> std::path::PathBuf {
|
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();
|
let mut path = std::env::temp_dir();
|
||||||
path.push(format!(
|
path.push(format!(
|
||||||
"optimizer_journal_test_{}.jsonl",
|
"optimizer_journal_test_{}_{}.jsonl",
|
||||||
std::time::SystemTime::now()
|
std::process::id(),
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
COUNTER.fetch_add(1, Ordering::Relaxed)
|
||||||
.unwrap()
|
|
||||||
.as_nanos()
|
|
||||||
));
|
));
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user