Skip to content

Commit

Permalink
Wait for background refresh in testAutomaticRefresh (#45661)
Browse files Browse the repository at this point in the history
If the background refresh is running, but not finished yet then the
document might not be visible to the next search. Thus, if
scheduledRefresh returns false, we need to wait until the background
refresh is done.

Closes #45571
  • Loading branch information
dnhatn authored Aug 20, 2019
1 parent d66a307 commit dc6e3e2
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,16 @@ public void testAutomaticRefresh() throws InterruptedException {
// with ZERO we are guaranteed to see the doc since we will wait for a refresh in the background
assertFalse(hasRefreshed);
assertTrue(shard.isSearchIdle());
} else if (randomTimeValue == null){
// with null we are guaranteed to see the doc since do execute the refresh.
// we can't assert on hasRefreshed since it might have been refreshed in the background on the shard concurrently
assertFalse(shard.isSearchIdle());
} else {
if (randomTimeValue == null) {
assertFalse(shard.isSearchIdle());
}
// we can't assert on hasRefreshed since it might have been refreshed in the background on the shard concurrently.
// and if the background refresh wins the refresh race (both call maybeRefresh), the document might not be visible
// until the background refresh is done.
if (hasRefreshed == false) {
ensureNoPendingScheduledRefresh(indexService.getThreadPool());
}
}
CountDownLatch started = new CountDownLatch(1);
Thread t = new Thread(() -> {
Expand Down

0 comments on commit dc6e3e2

Please sign in to comment.