From 37228f924a9f32adcda8a97a7efd915f787d835a Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Mon, 31 Oct 2016 14:04:18 +0100 Subject: [PATCH] [TEST] Use assertBusy to check assertMaster property in presence of a low publish timeout The assertion assertMaster checks if all nodes have each other in the cluster state and the correct master set. It is usually called after a disruption has been healed and ensureStableCluster been called. In presence of a low publish timeout of 1s in this test class, publishing might not be fully done even after ensureStableCluster returns. This commit adds an assertBusy to assertMaster so that the node has a bit more time to apply the cluster state from the master, even if it's a bit slow. --- .../DiscoveryWithServiceDisruptionsIT.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java index 2ca9f6f3384..5af2e1c6624 100644 --- a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java @@ -761,15 +761,7 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase { oldMasterNodeSteppedDown.await(30, TimeUnit.SECONDS); // Make sure that the end state is consistent on all nodes: assertDiscoveryCompleted(nodes); - // Use assertBusy(...) because the unfrozen node may take a while to actually join the cluster. - // The assertDiscoveryCompleted(...) can't know if all nodes have the old master node in all of the local cluster states - assertBusy(new Runnable() { - @Override - public void run() { - assertMaster(newMasterNode, nodes); - } - }); - + assertMaster(newMasterNode, nodes); assertThat(masters.size(), equalTo(2)); for (Map.Entry>> entry : masters.entrySet()) { @@ -1366,14 +1358,16 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase { }, 10, TimeUnit.SECONDS); } - private void assertMaster(String masterNode, List nodes) { - for (String node : nodes) { - ClusterState state = getNodeClusterState(node); - String failMsgSuffix = "cluster_state:\n" + state.prettyPrint(); - assertThat("wrong node count on [" + node + "]. " + failMsgSuffix, state.nodes().getSize(), equalTo(nodes.size())); - String otherMasterNodeName = state.nodes().getMasterNode() != null ? state.nodes().getMasterNode().getName() : null; - assertThat("wrong master on node [" + node + "]. " + failMsgSuffix, otherMasterNodeName, equalTo(masterNode)); - } + private void assertMaster(String masterNode, List nodes) throws Exception { + assertBusy(() -> { + for (String node : nodes) { + ClusterState state = getNodeClusterState(node); + String failMsgSuffix = "cluster_state:\n" + state.prettyPrint(); + assertThat("wrong node count on [" + node + "]. " + failMsgSuffix, state.nodes().getSize(), equalTo(nodes.size())); + String otherMasterNodeName = state.nodes().getMasterNode() != null ? state.nodes().getMasterNode().getName() : null; + assertThat("wrong master on node [" + node + "]. " + failMsgSuffix, otherMasterNodeName, equalTo(masterNode)); + } + }); } private void assertDiscoveryCompleted(List nodes) throws InterruptedException {