Skip to content

Commit 9b9f33e

Browse files
author
Hendrik Muhs
authored
[Transform] fix issue in TransformIndexerStateTests.testStopAtCheckpoint (#63006)
fix a test issue by improving counting the number of times the deferred listener is called fixes #62996
1 parent b450d23 commit 9b9f33e

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformIndexerStateTests.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,20 +412,29 @@ public void testStopAtCheckpoint() throws Exception {
412412
CountDownLatch searchLatch = indexer.createAwaitForSearchLatch(1);
413413

414414
List<CountDownLatch> responseLatches = new ArrayList<>();
415+
int timesStopAtCheckpointChanged = 0;
416+
// default stopAtCheckpoint is false
417+
boolean previousStopAtCheckpoint = false;
418+
415419
for (int i = 0; i < 3; ++i) {
416420
CountDownLatch latch = new CountDownLatch(1);
417421
boolean stopAtCheckpoint = randomBoolean();
422+
timesStopAtCheckpointChanged += (stopAtCheckpoint == previousStopAtCheckpoint ? 0 : 1);
423+
previousStopAtCheckpoint = stopAtCheckpoint;
418424
countResponse(listener -> setStopAtCheckpoint(indexer, stopAtCheckpoint, listener), latch);
419425
responseLatches.add(latch);
420426
}
421427

422428
// now let the indexer run again
423429
searchLatch.countDown();
424430

425-
// this time call it 3 times
426-
assertResponse(listener -> setStopAtCheckpoint(indexer, randomBoolean(), listener));
427-
assertResponse(listener -> setStopAtCheckpoint(indexer, randomBoolean(), listener));
428-
assertResponse(listener -> setStopAtCheckpoint(indexer, randomBoolean(), listener));
431+
// call it 3 times again
432+
for (int i = 0; i < 3; ++i) {
433+
boolean stopAtCheckpoint = randomBoolean();
434+
timesStopAtCheckpointChanged += (stopAtCheckpoint == previousStopAtCheckpoint ? 0 : 1);
435+
previousStopAtCheckpoint = stopAtCheckpoint;
436+
assertResponse(listener -> setStopAtCheckpoint(indexer, stopAtCheckpoint, listener));
437+
}
429438

430439
indexer.stop();
431440
assertBusy(() -> assertThat(indexer.getState(), equalTo(IndexerState.STOPPED)), 5, TimeUnit.SECONDS);
@@ -435,8 +444,9 @@ public void testStopAtCheckpoint() throws Exception {
435444
assertTrue("timed out after 5s", l.await(5, TimeUnit.SECONDS));
436445
}
437446

438-
// listener must have been called by the indexing thread between 1 and 6 times
439-
assertThat(indexer.getSaveStateListenerCallCount(), greaterThanOrEqualTo(1));
447+
// listener must have been called by the indexing thread between timesStopAtCheckpointChanged and 6 times
448+
// this is not exact, because we do not know _when_ the other thread persisted the flag
449+
assertThat(indexer.getSaveStateListenerCallCount(), greaterThanOrEqualTo(timesStopAtCheckpointChanged));
440450
assertThat(indexer.getSaveStateListenerCallCount(), lessThanOrEqualTo(6));
441451
}
442452
}

0 commit comments

Comments
 (0)