[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
This commit is contained in:
Hendrik Muhs 2020-09-30 08:51:00 +02:00
parent 2f5a813589
commit df93f46888
1 changed files with 16 additions and 6 deletions

View File

@ -412,9 +412,15 @@ public class TransformIndexerStateTests extends ESTestCase {
CountDownLatch searchLatch = indexer.createAwaitForSearchLatch(1); CountDownLatch searchLatch = indexer.createAwaitForSearchLatch(1);
List<CountDownLatch> responseLatches = new ArrayList<>(); List<CountDownLatch> responseLatches = new ArrayList<>();
int timesStopAtCheckpointChanged = 0;
// default stopAtCheckpoint is false
boolean previousStopAtCheckpoint = false;
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
boolean stopAtCheckpoint = randomBoolean(); boolean stopAtCheckpoint = randomBoolean();
timesStopAtCheckpointChanged += (stopAtCheckpoint == previousStopAtCheckpoint ? 0 : 1);
previousStopAtCheckpoint = stopAtCheckpoint;
countResponse(listener -> setStopAtCheckpoint(indexer, stopAtCheckpoint, listener), latch); countResponse(listener -> setStopAtCheckpoint(indexer, stopAtCheckpoint, listener), latch);
responseLatches.add(latch); responseLatches.add(latch);
} }
@ -422,10 +428,13 @@ public class TransformIndexerStateTests extends ESTestCase {
// now let the indexer run again // now let the indexer run again
searchLatch.countDown(); searchLatch.countDown();
// this time call it 3 times // call it 3 times again
assertResponse(listener -> setStopAtCheckpoint(indexer, randomBoolean(), listener)); for (int i = 0; i < 3; ++i) {
assertResponse(listener -> setStopAtCheckpoint(indexer, randomBoolean(), listener)); boolean stopAtCheckpoint = randomBoolean();
assertResponse(listener -> setStopAtCheckpoint(indexer, randomBoolean(), listener)); timesStopAtCheckpointChanged += (stopAtCheckpoint == previousStopAtCheckpoint ? 0 : 1);
previousStopAtCheckpoint = stopAtCheckpoint;
assertResponse(listener -> setStopAtCheckpoint(indexer, stopAtCheckpoint, listener));
}
indexer.stop(); indexer.stop();
assertBusy(() -> assertThat(indexer.getState(), equalTo(IndexerState.STOPPED)), 5, TimeUnit.SECONDS); assertBusy(() -> assertThat(indexer.getState(), equalTo(IndexerState.STOPPED)), 5, TimeUnit.SECONDS);
@ -435,8 +444,9 @@ public class TransformIndexerStateTests extends ESTestCase {
assertTrue("timed out after 5s", l.await(5, TimeUnit.SECONDS)); assertTrue("timed out after 5s", l.await(5, TimeUnit.SECONDS));
} }
// listener must have been called by the indexing thread between 1 and 6 times // listener must have been called by the indexing thread between timesStopAtCheckpointChanged and 6 times
assertThat(indexer.getSaveStateListenerCallCount(), greaterThanOrEqualTo(1)); // this is not exact, because we do not know _when_ the other thread persisted the flag
assertThat(indexer.getSaveStateListenerCallCount(), greaterThanOrEqualTo(timesStopAtCheckpointChanged));
assertThat(indexer.getSaveStateListenerCallCount(), lessThanOrEqualTo(6)); assertThat(indexer.getSaveStateListenerCallCount(), lessThanOrEqualTo(6));
} }
} }