Browse Source

[CI] wait for initializing shards on teardown in ESSingleNodeTestCase (#69186)

ensure shards aren't initializing at test teardown, so indexes that are initializing are not missed
for deletion.

fixes #69057
Hendrik Muhs 4 years ago
parent
commit
d0ea206e30

+ 19 - 1
test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java

@@ -41,6 +41,7 @@ import org.elasticsearch.node.NodeValidationException;
 import org.elasticsearch.plugins.Plugin;
 import org.elasticsearch.script.MockScriptService;
 import org.elasticsearch.search.internal.SearchContext;
+import org.elasticsearch.test.rest.ESRestTestCase;
 import org.elasticsearch.transport.TransportSettings;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -114,6 +115,7 @@ public abstract class ESSingleNodeTestCase extends ESTestCase {
     @Override
     public void tearDown() throws Exception {
         logger.trace("[{}#{}]: cleaning up after test", getTestClass().getSimpleName(), getTestName());
+        ensureNoInitializingShards();
         super.tearDown();
         assertAcked(
             client().admin().indices().prepareDelete("*")
@@ -324,7 +326,6 @@ public abstract class ESSingleNodeTestCase extends ESTestCase {
         return ensureGreen(TimeValue.timeValueSeconds(30), indices);
     }
 
-
     /**
      * Ensures the cluster has a green state via the cluster health API. This method will also wait for relocations.
      * It is useful to ensure that all action on the cluster have finished and all shards that were currently relocating
@@ -355,4 +356,21 @@ public abstract class ESSingleNodeTestCase extends ESTestCase {
         return true;
     }
 
+
+    /**
+     * waits until all shard initialization is completed.
+     *
+     * inspired by {@link ESRestTestCase}
+     *
+     * @throws IOException
+     */
+    protected void ensureNoInitializingShards() throws IOException {
+        ClusterHealthResponse actionGet = client().admin()
+            .cluster()
+            .health(Requests.clusterHealthRequest("_all").waitForNoInitializingShards(true))
+            .actionGet();
+
+        assertFalse("timed out waiting for shards to initialize", actionGet.isTimedOut());
+    }
+
 }