Skip to content

Commit fcac3fb

Browse files
committed
AutoFollowIT should not rely on assertBusy but should use latches instead (#49141)
AutoFollowIT relies on assertBusy() calls to wait for a given number of leader indices to be created but this is prone to failures on CI. Instead, we should use latches to indicate when auto-follow patterns must be paused and resumed.
1 parent 805c31e commit fcac3fb

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

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

+19-6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Collections;
3737
import java.util.List;
3838
import java.util.Locale;
39+
import java.util.concurrent.CountDownLatch;
3940
import java.util.concurrent.TimeUnit;
4041
import java.util.concurrent.atomic.AtomicBoolean;
4142
import java.util.concurrent.atomic.AtomicInteger;
@@ -499,6 +500,9 @@ public void testPauseAndResumeWithMultipleAutoFollowPatterns() throws Exception
499500

500501
final AtomicBoolean running = new AtomicBoolean(true);
501502
final AtomicInteger leaderIndices = new AtomicInteger(0);
503+
final CountDownLatch latchThree = new CountDownLatch(3);
504+
final CountDownLatch latchSix = new CountDownLatch(6);
505+
final CountDownLatch latchNine = new CountDownLatch(9);
502506

503507
// start creating new indices on the remote cluster
504508
final Thread createNewLeaderIndicesThread = new Thread(() -> {
@@ -513,6 +517,9 @@ public void testPauseAndResumeWithMultipleAutoFollowPatterns() throws Exception
513517
} else {
514518
Thread.sleep(200L);
515519
}
520+
latchThree.countDown();
521+
latchSix.countDown();
522+
latchNine.countDown();
516523
} catch (Exception e) {
517524
throw new AssertionError(e);
518525
}
@@ -521,23 +528,29 @@ public void testPauseAndResumeWithMultipleAutoFollowPatterns() throws Exception
521528
createNewLeaderIndicesThread.start();
522529

523530
// wait for 3 leader indices to be created on the remote cluster
524-
assertBusy(() -> assertThat(leaderIndices.get(), greaterThanOrEqualTo(3)));
525-
assertBusy(() -> assertThat(getAutoFollowStats().getNumberOfSuccessfulFollowIndices(), greaterThanOrEqualTo(3L)));
531+
latchThree.await(30L, TimeUnit.SECONDS);
532+
assertThat(leaderIndices.get(), greaterThanOrEqualTo(3));
533+
assertBusy(() -> assertThat(getAutoFollowStats().getNumberOfSuccessfulFollowIndices(), greaterThanOrEqualTo(3L)),
534+
30L, TimeUnit.SECONDS);
526535

527536
// now pause some random patterns
528537
pausedAutoFollowerPatterns.forEach(this::pauseAutoFollowPattern);
529538
assertBusy(() -> autoFollowPatterns.forEach(pattern ->
530-
assertThat(getAutoFollowPattern(pattern).isActive(), equalTo(pausedAutoFollowerPatterns.contains(pattern) == false))));
539+
assertThat(getAutoFollowPattern(pattern).isActive(), equalTo(pausedAutoFollowerPatterns.contains(pattern) == false))),
540+
30L, TimeUnit.SECONDS);
531541

532542
// wait for more leader indices to be created on the remote cluster
533-
assertBusy(() -> assertThat(leaderIndices.get(), greaterThanOrEqualTo(6)));
543+
latchSix.await(30L, TimeUnit.SECONDS);
544+
assertThat(leaderIndices.get(), greaterThanOrEqualTo(6));
534545

535546
// resume auto follow patterns
536547
pausedAutoFollowerPatterns.forEach(this::resumeAutoFollowPattern);
537-
assertBusy(() -> autoFollowPatterns.forEach(pattern -> assertTrue(getAutoFollowPattern(pattern).isActive())));
548+
assertBusy(() -> autoFollowPatterns.forEach(pattern -> assertTrue(getAutoFollowPattern(pattern).isActive())),
549+
30L, TimeUnit.SECONDS);
538550

539551
// wait for more leader indices to be created on the remote cluster
540-
assertBusy(() -> assertThat(leaderIndices.get(), greaterThanOrEqualTo(9)));
552+
latchNine.await(30L, TimeUnit.SECONDS);
553+
assertThat(leaderIndices.get(), greaterThanOrEqualTo(9));
541554
assertBusy(() -> assertThat(getAutoFollowStats().getNumberOfSuccessfulFollowIndices(), greaterThanOrEqualTo(9L)),
542555
30L, TimeUnit.SECONDS);
543556

0 commit comments

Comments
 (0)