mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Valery Kharseko
3 hours ago 7367aa439db9731c364a256444f0afa1c61973a4
[#1273] Fix expected CSN list race in HistoricalCsnOrderingTest (#1274)

Fixes #1273.

`aRecoveryASessionWhichStartedMeanwhileNeedsIsNotEnded` compared the
changelog with an expected CSN list while the publisher hook could still
append to it. This could throw `ConcurrentModificationException` in
AssertJ or accept the initial one-change list before the second change
was recorded.

Wait up to 30 seconds for the hook to record the second CSN, then
compare against a stable snapshot of the complete list. The latch
establishes visibility between the publisher and test threads; the
bounded retry for changelog convergence remains.

Validation: Java 11, reactor `verify -Pprecommit -pl
opendj-server-legacy -am` with `-Dit.test=HistoricalCsnOrderingTest`: 70
tests passed, no failures, errors, or skips. `git diff --check` passed.
1 files modified
7 ■■■■■ changed files
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalCsnOrderingTest.java 7 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalCsnOrderingTest.java
@@ -1827,6 +1827,7 @@
    LDAPReplicationDomain rd1 = createReplicationDomain(serverId);
    final CountDownLatch held = new CountDownLatch(1);
    final CountDownLatch release = new CountDownLatch(1);
    final CountDownLatch changeDone = new CountDownLatch(1);
    try
    {
      second = createIsolatedReplicationServer(secondPort, "HistoricalCsnOrderingSecond", SECOND_RS_ID);
@@ -1859,11 +1860,15 @@
          {
            replace(dnA, "displayName", "once the publisher ran on the session before");
            done.add(rd1.getLastLocalChange());
            changeDone.countDown();
          }).run();
        }
      });
      release.countDown();
      // Wait for both expected CSNs before reading the list the publisher updates.
      assertTrue(changeDone.await(30, SECONDS), "the publisher recorded the second change");
      final List<CSN> expected = new ArrayList<>(done);
      final ReplicationServer secondRs = second;
      new TestTimer.Builder()
          .maxSleep(30, SECONDS)
@@ -1871,7 +1876,7 @@
          .toTimer()
          .repeatUntilSuccess(() -> assertThat(changelogAfter(secondRs, baseDN, onBoth))
              .as("the changes the second replication server holds after the one it had")
              .isEqualTo(done));
              .isEqualTo(expected));
      waitUntilTheRecoveryIsOver(rd1);
    }
    finally