Browse Source

[Test] Wait for shards before asserting number of docs (#95689)

This PR makes the test wait for all target indices before asserting
the number of documents in them.
Yang Wang 2 years ago
parent
commit
c57a18b1c0

+ 12 - 5
x-pack/plugin/security/qa/multi-cluster/src/javaRestTest/java/org/elasticsearch/xpack/remotecluster/RemoteClusterSecurityCcrIT.java

@@ -238,16 +238,17 @@ public class RemoteClusterSecurityCcrIT extends AbstractRemoteClusterSecurityTes
                 { "index": { "_index": "metrics-001" } }
                 { "name": "doc-3" }
                 { "index": { "_index": "metrics-002" } }
-                { "name": "doc-4" }\n"""));
+                { "name": "doc-4" }
+                """));
             assertOK(performRequestAgainstFulfillingCluster(bulkRequest));
         }
 
         // follow cluster
         {
             assertBusy(() -> {
-                ensureHealth("", request -> {
+                ensureHealth("metrics-000,metrics-002", request -> {
                     request.addParameter("wait_for_status", "yellow");
-                    request.addParameter("wait_for_active_shards", "1");
+                    request.addParameter("wait_for_active_shards", "2");
                     request.addParameter("wait_for_no_relocating_shards", "true");
                     request.addParameter("wait_for_no_initializing_shards", "true");
                     request.addParameter("timeout", "5s");
@@ -273,7 +274,8 @@ public class RemoteClusterSecurityCcrIT extends AbstractRemoteClusterSecurityTes
                 { "index": { "_index": "metrics-000" } }
                 { "name": "doc-5" }
                 { "index": { "_index": "metrics-002" } }
-                { "name": "doc-6" }\n"""));
+                { "name": "doc-6" }
+                """));
             assertOK(performRequestAgainstFulfillingCluster(bulkRequest));
             verifyReplicatedDocuments(5L, "metrics-000", "metrics-002");
 
@@ -295,7 +297,12 @@ public class RemoteClusterSecurityCcrIT extends AbstractRemoteClusterSecurityTes
     private void verifyReplicatedDocuments(long numberOfDocs, String... indices) throws Exception {
         final Request searchRequest = new Request("GET", "/" + arrayToCommaDelimitedString(indices) + "/_search");
         assertBusy(() -> {
-            final Response response = performRequestWithCcrUser(searchRequest);
+            final Response response;
+            try {
+                response = performRequestWithCcrUser(searchRequest);
+            } catch (ResponseException e) {
+                throw new AssertionError(e);
+            }
             assertOK(response);
             final SearchResponse searchResponse = SearchResponse.fromXContent(responseAsParser(response));
             assertThat(searchResponse.getHits().getTotalHits().value, equalTo(numberOfDocs));