diff --git a/aw-sync/tests/sync_roundtrip.rs b/aw-sync/tests/sync_roundtrip.rs index ee4733f2..cfebc5ec 100644 --- a/aw-sync/tests/sync_roundtrip.rs +++ b/aw-sync/tests/sync_roundtrip.rs @@ -10,21 +10,32 @@ /// /// Both copies then render in /timeline, so every event is shown twice. use std::path::PathBuf; +use std::sync::atomic::{AtomicU64, Ordering}; use aw_datastore::Datastore; use aw_models::{Bucket, BucketMetadata}; use aw_sync::{sync_datastores, AccessMethod, SyncSpec}; +// Tests in this binary run in parallel. Use a monotonic counter to guarantee +// each datastore gets a unique path even when two tests start within the same +// clock tick (seen on macOS where SystemTime resolution can be coarser than +// nanoseconds, causing path collisions and SQLite migration races). +static DB_COUNTER: AtomicU64 = AtomicU64::new(0); + fn tmp_db(name: &str) -> PathBuf { let mut p = std::env::temp_dir(); + // Combine a per-process counter (within-run uniqueness) with a timestamp + // (cross-run uniqueness when the PID is reused and the counter resets to 0). + let ts = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos(); p.push(format!( - "aw-sync-roundtrip-{}-{}-{}.db", + "aw-sync-roundtrip-{}-{}-{}-{}.db", std::process::id(), name, - std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .unwrap() - .as_nanos() + DB_COUNTER.fetch_add(1, Ordering::Relaxed), + ts, )); p }