Browse Source

Fix AutoFollowIT (#49025)

This commit fixes an off-by-one bug in the AutoFollowIT test that causes 
failures because the leaderIndices counter is incremented during the evaluation 
of the leaderIndices.incrementAndGet() < 20 condition but the 20th index is 
not created, making the final assertion not verified.

It also gives a bit more time for cluster state updates to be processed on the 
follower cluster.

Closes #48982
Tanguy Leroux 6 years ago
parent
commit
86d83c6b98

+ 5 - 7
x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java

@@ -491,16 +491,14 @@ public class AutoFollowIT extends CcrIntegTestCase {
 
         // start creating new indices on the remote cluster
         final Thread createNewLeaderIndicesThread = new Thread(() -> {
-            int leaderIndicesCount;
-            while (running.get() && (leaderIndicesCount = leaderIndices.incrementAndGet()) < 20) {
+            while (running.get() && leaderIndices.get() < 20) {
                 final String prefix = randomFrom(prefixes);
-                final String leaderIndex = prefix + leaderIndicesCount;
+                final String leaderIndex = prefix + leaderIndices.incrementAndGet();
                 try {
                     createLeaderIndex(leaderIndex, leaderIndexSettings);
                     ensureLeaderGreen(leaderIndex);
                     if (pausedAutoFollowerPatterns.stream().noneMatch(pattern -> pattern.startsWith(prefix))) {
-                        final String followingIndex = "copy-" + leaderIndex;
-                        assertBusy(() -> assertTrue(ESIntegTestCase.indexExists(followingIndex, followerClient())));
+                        ensureFollowerGreen("copy-" + leaderIndex);
                     } else {
                         Thread.sleep(200L);
                     }
@@ -522,7 +520,6 @@ public class AutoFollowIT extends CcrIntegTestCase {
 
         // wait for more leader indices to be created on the remote cluster
         assertBusy(() -> assertThat(leaderIndices.get(), greaterThanOrEqualTo(6)));
-        assertBusy(() -> assertThat(getAutoFollowStats().getNumberOfSuccessfulFollowIndices(), greaterThanOrEqualTo(6L)));
 
         // resume auto follow patterns
         pausedAutoFollowerPatterns.forEach(this::resumeAutoFollowPattern);
@@ -530,7 +527,8 @@ public class AutoFollowIT extends CcrIntegTestCase {
 
         // wait for more leader indices to be created on the remote cluster
         assertBusy(() -> assertThat(leaderIndices.get(), greaterThanOrEqualTo(9)));
-        assertBusy(() -> assertThat(getAutoFollowStats().getNumberOfSuccessfulFollowIndices(), greaterThanOrEqualTo(9L)));
+        assertBusy(() -> assertThat(getAutoFollowStats().getNumberOfSuccessfulFollowIndices(), greaterThanOrEqualTo(9L)),
+            30L, TimeUnit.SECONDS);
 
         running.set(false);
         createNewLeaderIndicesThread.join();