@@ -412,20 +412,29 @@ public void testStopAtCheckpoint() throws Exception {
412
412
CountDownLatch searchLatch = indexer .createAwaitForSearchLatch (1 );
413
413
414
414
List <CountDownLatch > responseLatches = new ArrayList <>();
415
+ int timesStopAtCheckpointChanged = 0 ;
416
+ // default stopAtCheckpoint is false
417
+ boolean previousStopAtCheckpoint = false ;
418
+
415
419
for (int i = 0 ; i < 3 ; ++i ) {
416
420
CountDownLatch latch = new CountDownLatch (1 );
417
421
boolean stopAtCheckpoint = randomBoolean ();
422
+ timesStopAtCheckpointChanged += (stopAtCheckpoint == previousStopAtCheckpoint ? 0 : 1 );
423
+ previousStopAtCheckpoint = stopAtCheckpoint ;
418
424
countResponse (listener -> setStopAtCheckpoint (indexer , stopAtCheckpoint , listener ), latch );
419
425
responseLatches .add (latch );
420
426
}
421
427
422
428
// now let the indexer run again
423
429
searchLatch .countDown ();
424
430
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
+ }
429
438
430
439
indexer .stop ();
431
440
assertBusy (() -> assertThat (indexer .getState (), equalTo (IndexerState .STOPPED )), 5 , TimeUnit .SECONDS );
@@ -435,8 +444,9 @@ public void testStopAtCheckpoint() throws Exception {
435
444
assertTrue ("timed out after 5s" , l .await (5 , TimeUnit .SECONDS ));
436
445
}
437
446
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 ));
440
450
assertThat (indexer .getSaveStateListenerCallCount (), lessThanOrEqualTo (6 ));
441
451
}
442
452
}
0 commit comments