From 08c730535481e1b982b5532a438a6779fe33dc88 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Thu, 26 Nov 2026 14:54:55 +0000
Subject: [PATCH] Fix timing races in replication recovery tests (#1333)

---
 opendj-server-legacy/src/test/java/org/opends/server/replication/server/MissedUpdateRecoveryTest.java  |    5 ++---
 opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalCsnOrderingTest.java |    6 +++++-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalCsnOrderingTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalCsnOrderingTest.java
index 63f1b32..9cf9b42 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalCsnOrderingTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalCsnOrderingTest.java
@@ -1086,25 +1086,29 @@
 
       // The session started again recovers them, and the first round of its recovery fails, with a
       // change done meanwhile: the recovery keeps it, and the next one publishes it.
+      final CountDownLatch changeDone = new CountDownLatch(1);
       rd1.setMissingChangesSearchHook(onTheFirstSearch(search ->
       {
         unchecked(() ->
         {
           replace(dnA, "displayName", "while the failing round searches");
           done.add(rd1.getLastLocalChange());
+          changeDone.countDown();
         }).run();
         failure.accept(search);
       }));
       rd1.disable();
       rd1.enable();
 
+      assertTrue(changeDone.await(30, SECONDS), "the publisher recorded the third change");
+      final List<CSN> expected = List.copyOf(done);
       new TestTimer.Builder()
           .maxSleep(30, SECONDS)
           .sleepTimes(100, MILLISECONDS)
           .toTimer()
           .repeatUntilSuccess(() -> assertThat(changelogAfter(rs, baseDN, rsMaxCSN))
               .as("the changes the replication server holds after the ones it had")
-              .isEqualTo(done));
+              .isEqualTo(expected));
       waitUntilTheRecoveryIsOver(rd1);
       replace(dnA, "description", "once the recovery is over");
       assertInTheChangelog(rs, baseDN, rd1.getLastLocalChange());
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/server/MissedUpdateRecoveryTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/server/MissedUpdateRecoveryTest.java
index ba74239..76232e8 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/server/MissedUpdateRecoveryTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/server/MissedUpdateRecoveryTest.java
@@ -130,9 +130,8 @@
           .as("the warning names the state of the replica and the state of the domain")
           .contains(ownCSN.toString())
           .contains(csn.toString());
-      assertThat(handler.isFollowing())
-          .as("the replica is served from the queue again once it has been sent the change")
-          .isTrue();
+      // The writer can deliver the change before it returns to the in-memory queue.
+      waitForFollowing(handler);
     }
     finally
     {

--
Gitblit v1.10.0