Skip to content

Commit 3cdfcb4

Browse files
committed
Fix testRelocateWhileContinuouslyIndexingAndWaitingForRefresh (#37560)
This test failed because the refresh at the end of the test is not guaranteed to run before the indexing is completed, and therefore there's no guarantee that the refresh will free all operations. This triggers an assertion failure in the test clean-up, which asserts that there are no more pending operations.
1 parent f905562 commit 3cdfcb4

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

server/src/test/java/org/elasticsearch/recovery/RelocationIT.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
2828
import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse;
2929
import org.elasticsearch.action.index.IndexRequestBuilder;
30+
import org.elasticsearch.action.index.IndexResponse;
3031
import org.elasticsearch.action.search.SearchResponse;
3132
import org.elasticsearch.action.support.WriteRequest;
3233
import org.elasticsearch.client.Client;
@@ -552,7 +553,7 @@ public void testRelocateWhileWaitingForRefresh() {
552553
assertThat(client().prepareSearch("test").setSize(0).execute().actionGet().getHits().getTotalHits(), equalTo(20L));
553554
}
554555

555-
public void testRelocateWhileContinuouslyIndexingAndWaitingForRefresh() {
556+
public void testRelocateWhileContinuouslyIndexingAndWaitingForRefresh() throws Exception {
556557
logger.info("--> starting [node1] ...");
557558
final String node1 = internalCluster().startNode();
558559

@@ -570,9 +571,11 @@ public void testRelocateWhileContinuouslyIndexingAndWaitingForRefresh() {
570571
logger.info("--> flush so we have an actual index");
571572
client().admin().indices().prepareFlush().execute().actionGet();
572573
logger.info("--> index more docs so we have something in the translog");
574+
final List<ActionFuture<IndexResponse>> pendingIndexResponses = new ArrayList<>();
573575
for (int i = 10; i < 20; i++) {
574-
client().prepareIndex("test", "type", Integer.toString(i)).setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL)
575-
.setSource("field", "value" + i).execute();
576+
pendingIndexResponses.add(client().prepareIndex("test", "type", Integer.toString(i))
577+
.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL)
578+
.setSource("field", "value" + i).execute());
576579
}
577580

578581
logger.info("--> start another node");
@@ -587,16 +590,21 @@ public void testRelocateWhileContinuouslyIndexingAndWaitingForRefresh() {
587590
.execute();
588591
logger.info("--> index 100 docs while relocating");
589592
for (int i = 20; i < 120; i++) {
590-
client().prepareIndex("test", "type", Integer.toString(i)).setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL)
591-
.setSource("field", "value" + i).execute();
593+
pendingIndexResponses.add(client().prepareIndex("test", "type", Integer.toString(i))
594+
.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL)
595+
.setSource("field", "value" + i).execute());
592596
}
593597
relocationListener.actionGet();
594598
clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID)
595599
.setWaitForNoRelocatingShards(true).setTimeout(ACCEPTABLE_RELOCATION_TIME).execute().actionGet();
596600
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
597601

598602
logger.info("--> verifying count");
599-
client().admin().indices().prepareRefresh().execute().actionGet();
603+
assertBusy(() -> {
604+
client().admin().indices().prepareRefresh().execute().actionGet();
605+
assertTrue(pendingIndexResponses.stream().allMatch(ActionFuture::isDone));
606+
}, 1, TimeUnit.MINUTES);
607+
600608
assertThat(client().prepareSearch("test").setSize(0).execute().actionGet().getHits().getTotalHits(), equalTo(120L));
601609
}
602610

0 commit comments

Comments
 (0)