From bbbbe5b47e804d329ec78d864e8c306de26150a7 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 24 Aug 2026 20:09:49 +0000 Subject: [PATCH 1/2] fix(aw-sync): use atomic counter in test tmp_db to prevent parallel-test path collisions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tests in sync_roundtrip run in parallel. Both test_push_does_not_reexport_synced_buckets and test_own_data_does_not_return_via_peer call round_trip(), which calls datastore("a-local") etc. with the same names. The old tmp_db() used SystemTime nanoseconds, which can collide on macOS (lower clock resolution) — two parallel tests then share the same SQLite file and race on migrations, producing "duplicate column name: data". Replace the timestamp with a process-wide AtomicU64 counter. Each call to tmp_db() gets a unique value regardless of when it runs, eliminating the race. --- aw-sync/tests/sync_roundtrip.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/aw-sync/tests/sync_roundtrip.rs b/aw-sync/tests/sync_roundtrip.rs index ee4733f2..68d150b0 100644 --- a/aw-sync/tests/sync_roundtrip.rs +++ b/aw-sync/tests/sync_roundtrip.rs @@ -10,21 +10,25 @@ /// /// 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(); p.push(format!( "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), )); p } From d1a1a05a9cbbf8d9459942fe8f079ece962c9663 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 24 Aug 2026 20:49:24 +0000 Subject: [PATCH 2/2] fix(aw-sync): add timestamp to tmp_db path for cross-run uniqueness Counter resets to 0 on each process invocation; combining it with a nanosecond timestamp means paths are unique across separate test runs even when the PID is reused, addressing the Greptile P2 concern. The counter still provides the within-run parallel-test guarantee. No new dependencies required. --- aw-sync/tests/sync_roundtrip.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/aw-sync/tests/sync_roundtrip.rs b/aw-sync/tests/sync_roundtrip.rs index 68d150b0..cfebc5ec 100644 --- a/aw-sync/tests/sync_roundtrip.rs +++ b/aw-sync/tests/sync_roundtrip.rs @@ -24,11 +24,18 @@ 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, DB_COUNTER.fetch_add(1, Ordering::Relaxed), + ts, )); p }