Skip to content

Commit b5ee69d

Browse files
authored
Fix intermittent failures in CrossClusterAsyncSearchIT (#142781) (#142867)
(cherry picked from commit cf1cf4c) # Conflicts: # muted-tests.yml
1 parent 2db163e commit b5ee69d

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

x-pack/plugin/async-search/src/internalClusterTest/java/org/elasticsearch/xpack/search/CrossClusterAsyncSearchIT.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.ExceptionsHelper;
1111
import org.elasticsearch.ResourceNotFoundException;
1212
import org.elasticsearch.action.ActionFuture;
13+
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
1314
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest;
1415
import org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskRequest;
1516
import org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskResponse;
@@ -1940,14 +1941,19 @@ private Map<String, Object> setupTwoClusters() {
19401941
.setSettings(Settings.builder().put(remoteSettings.build()))
19411942
.setMapping("@timestamp", "type=date", "f", "type=text")
19421943
);
1943-
assertFalse(
1944-
client(REMOTE_CLUSTER).admin()
1945-
.cluster()
1946-
.prepareHealth(TEST_REQUEST_TIMEOUT, remoteIndex)
1947-
.setWaitForYellowStatus()
1948-
.setTimeout(TimeValue.timeValueSeconds(10))
1949-
.get()
1950-
.isTimedOut()
1944+
// Wait for yellow and no initializing shards so all assigned shards are STARTED before tests run searches.
1945+
ClusterHealthResponse healthResponse = client(REMOTE_CLUSTER).admin()
1946+
.cluster()
1947+
.prepareHealth(TEST_REQUEST_TIMEOUT, remoteIndex)
1948+
.setWaitForYellowStatus()
1949+
.setWaitForNoInitializingShards(true)
1950+
.setTimeout(TimeValue.timeValueSeconds(10))
1951+
.get();
1952+
assertFalse("remote index health check timed out", healthResponse.isTimedOut());
1953+
assertEquals(
1954+
"remote index should have no initializing shards, had: " + healthResponse.getInitializingShards(),
1955+
0,
1956+
healthResponse.getInitializingShards()
19511957
);
19521958
indexDocs(client(REMOTE_CLUSTER), remoteIndex);
19531959

0 commit comments

Comments
 (0)