Wait for background refresh in testAutomaticRefresh (#45661)

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
This commit is contained in:
Nhat Nguyen 2019-08-20 09:13:46 -04:00
parent 99b21d50b8
commit e9759b2b33
1 changed files with 10 additions and 4 deletions

View File

@ -710,11 +710,17 @@ public class IndexShardIT extends ESSingleNodeTestCase {
// 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
} 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(() -> {
SearchResponse searchResponse;