Browse Source

Dump cluster state if ensureGreen timed out in QA tests (#40133)

When the method ensureGreen in QA tests is timed out, it does not
provide enough info for us to investigate why the testing index is
not green yet. With this change, we will dump the cluster state if
ensureGreen timed out.

Relates #32027
Nhat Nguyen 6 years ago
parent
commit
7893aaec0c

+ 14 - 1
test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

@@ -805,7 +805,20 @@ public abstract class ESRestTestCase extends ESTestCase {
         request.addParameter("wait_for_no_relocating_shards", "true");
         request.addParameter("timeout", "70s");
         request.addParameter("level", "shards");
-        client().performRequest(request);
+        try {
+            client().performRequest(request);
+        } catch (ResponseException e) {
+            if (e.getResponse().getStatusLine().getStatusCode() == HttpStatus.SC_REQUEST_TIMEOUT) {
+                try {
+                    final Response clusterStateResponse = client().performRequest(new Request("GET", "/_cluster/state"));
+                    fail("timed out waiting for green state for index [" + index + "] " +
+                        "cluster state [" + EntityUtils.toString(clusterStateResponse.getEntity()) + "]");
+                } catch (Exception inner) {
+                    e.addSuppressed(inner);
+                }
+            }
+            throw e;
+        }
     }
 
     /**