Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions aw-sync/tests/sync_roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Counter paths repeat across runs

If a previous test run leaves its SQLite files in the shared temporary directory and a later invocation receives the same process ID, DB_COUNTER restarts at zero and reuses those paths, causing tests to open stale buckets and events instead of fresh databases.

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
}
Expand Down
Loading