From 4cbd70913a9f198c96820aec2d069eaf299dcd1e Mon Sep 17 00:00:00 2001 From: pasichdev Date: Mon, 5 Oct 2026 20:40:08 +0300 Subject: [PATCH] test(sync): stop the disconnect-lock test racing its own log runWhileNoSyncRuns_waitsForTheSyncInFlightToFinish recorded "sync finished" after the sync had already let go of the lock, so the wipe could log "cleared" first and the in-order check failed now and then. It stopped the 2.7.56 release build once. The test now checks what the lock guarantees: the wipe runs only after the sync has applied its snapshot, and both entries are there, in either order. Refs: #170 --- .../mynotes/data/sync/SyncServiceTest.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/test/java/com/pasich/mynotes/data/sync/SyncServiceTest.java b/app/src/test/java/com/pasich/mynotes/data/sync/SyncServiceTest.java index 8ed63e9..e1f5281 100644 --- a/app/src/test/java/com/pasich/mynotes/data/sync/SyncServiceTest.java +++ b/app/src/test/java/com/pasich/mynotes/data/sync/SyncServiceTest.java @@ -350,8 +350,17 @@ public void runWhileNoSyncRuns_waitsForTheSyncInFlightToFinish() throws Exceptio syncing.start(); assertThat(backend.readStarted.await(5, java.util.concurrent.TimeUnit.SECONDS)).isTrue(); + java.util.concurrent.atomic.AtomicBoolean syncAppliedBeforeClear = + new java.util.concurrent.atomic.AtomicBoolean(); Thread clearing = - new Thread(() -> SyncService.runWhileNoSyncRuns(() -> order.add("cleared"))); + new Thread( + () -> + SyncService.runWhileNoSyncRuns( + () -> { + syncAppliedBeforeClear.set( + store.appliedSnapshot != null); + order.add("cleared"); + })); clearing.start(); Thread.sleep(200L); @@ -360,7 +369,10 @@ public void runWhileNoSyncRuns_waitsForTheSyncInFlightToFinish() throws Exceptio backend.readReleased.countDown(); syncing.join(5_000L); clearing.join(5_000L); - assertThat(order).containsExactly("sync finished", "cleared").inOrder(); + // "sync finished" is recorded after the sync lets go of the lock, so it may land on either + // side of "cleared"; what matters is that the wipe ran only once the sync had applied. + assertThat(order).containsExactly("sync finished", "cleared"); + assertThat(syncAppliedBeforeClear.get()).isTrue(); assertThat(store.appliedSnapshot).isNotNull(); }