[TEST] Don't start thread before checking for pending refresh

If we start the thread too early it registers a refresh listener and
that causes out assertion to fail if there is a zero timeout.
Closes #27769
This commit is contained in:
Simon Willnauer 2017-12-15 09:25:19 +01:00
parent 54b1fed5b3
commit 1e5d3787e5
1 changed files with 10 additions and 10 deletions

View File

@ -614,16 +614,6 @@ public class IndexShardIT extends ESSingleNodeTestCase {
assertFalse(indexService.getIndexSettings().isExplicitRefresh()); assertFalse(indexService.getIndexSettings().isExplicitRefresh());
ensureGreen(); ensureGreen();
AtomicInteger totalNumDocs = new AtomicInteger(Integer.MAX_VALUE); AtomicInteger totalNumDocs = new AtomicInteger(Integer.MAX_VALUE);
CountDownLatch started = new CountDownLatch(1);
Thread t = new Thread(() -> {
SearchResponse searchResponse;
started.countDown();
do {
searchResponse = client().prepareSearch().get();
} while (searchResponse.getHits().totalHits != totalNumDocs.get());
});
t.start();
started.await();
assertNoSearchHits(client().prepareSearch().get()); assertNoSearchHits(client().prepareSearch().get());
int numDocs = scaledRandomIntBetween(25, 100); int numDocs = scaledRandomIntBetween(25, 100);
totalNumDocs.set(numDocs); totalNumDocs.set(numDocs);
@ -641,6 +631,16 @@ public class IndexShardIT extends ESSingleNodeTestCase {
// we can't assert on hasRefreshed since it might have been refreshed in the background on the shard concurrently // we can't assert on hasRefreshed since it might have been refreshed in the background on the shard concurrently
assertFalse(shard.isSearchIdle()); assertFalse(shard.isSearchIdle());
} }
CountDownLatch started = new CountDownLatch(1);
Thread t = new Thread(() -> {
SearchResponse searchResponse;
started.countDown();
do {
searchResponse = client().prepareSearch().get();
} while (searchResponse.getHits().totalHits != totalNumDocs.get());
});
t.start();
started.await();
assertHitCount(client().prepareSearch().get(), 1); assertHitCount(client().prepareSearch().get(), 1);
for (int i = 1; i < numDocs; i++) { for (int i = 1; i < numDocs; i++) {
client().prepareIndex("test", "test", "" + i).setSource("{\"foo\" : \"bar\"}", XContentType.JSON) client().prepareIndex("test", "test", "" + i).setSource("{\"foo\" : \"bar\"}", XContentType.JSON)