From a3cceb8a008c1a700dbf2a3be52e10033056b040 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Fri, 7 Apr 2017 15:23:04 +0200 Subject: [PATCH] [TEST] Fix testMultipleNodesShutdownNonMasterNodes to wait for the right nodes to rejoin the cluster This test was sporadically failing for the following reason: - 4 nodes (nodes 0, 1, 2, and 3) running with `minimum_master_nodes` set to 3 - we stop 2 nodes (node 0 and 3) - wait for cluster block to be in place on all nodes - start 2 nodes (node 4 and node 5) and do a `prepareHealth().setWaitForNodes("4")` - then do a search request The search request runs into the `ClusterBlockException` as the `prepareHealth().setWaitForNodes("4")` check succeeds on a cluster state that has nodes 1, 2, 3, and 4, i.e., only one of the two new nodes has joined the cluster and only one of the two dead nodes was removed by the master (removing the dead nodes only happens after there are again `minimum_master_nodes` nodes in the cluster). This commit fixes the issue by reusing a method from InternalTestCluster that checks that the right nodes have rejoined the cluster. --- .../java/org/elasticsearch/cluster/MinimumMasterNodesIT.java | 3 +-- .../main/java/org/elasticsearch/test/InternalTestCluster.java | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java b/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java index 450744d64df..71fe7caabcf 100644 --- a/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java @@ -249,8 +249,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase { String[] newNodes = internalCluster().startNodes(2, settings).stream().toArray(String[]::new); ensureGreen(); - clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForNodes("4").execute().actionGet(); - assertThat(clusterHealthResponse.isTimedOut(), equalTo(false)); + internalCluster().validateClusterFormed(); state = client().admin().cluster().prepareState().execute().actionGet().getState(); assertThat(state.nodes().getSize(), equalTo(4)); diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index cf9c2dc3515..c4e191e75c5 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -1059,13 +1059,13 @@ public final class InternalTestCluster extends TestCluster { } /** ensure a cluster is formed with all published nodes. */ - private void validateClusterFormed() { + public synchronized void validateClusterFormed() { String name = randomFrom(random, getNodeNames()); validateClusterFormed(name); } /** ensure a cluster is formed with all published nodes, but do so by using the client of the specified node */ - private void validateClusterFormed(String viaNode) { + public synchronized void validateClusterFormed(String viaNode) { Set expectedNodes = new HashSet<>(); for (NodeAndClient nodeAndClient : nodes.values()) { expectedNodes.add(getInstanceFromNode(ClusterService.class, nodeAndClient.node()).localNode());