[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.
This commit is contained in:
Yannick Welsch 2016-10-31 14:04:18 +01:00
parent e7cfe101e4
commit 37228f924a
1 changed files with 11 additions and 17 deletions

View File

@ -761,15 +761,7 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase {
oldMasterNodeSteppedDown.await(30, TimeUnit.SECONDS); oldMasterNodeSteppedDown.await(30, TimeUnit.SECONDS);
// Make sure that the end state is consistent on all nodes: // Make sure that the end state is consistent on all nodes:
assertDiscoveryCompleted(nodes); assertDiscoveryCompleted(nodes);
// Use assertBusy(...) because the unfrozen node may take a while to actually join the cluster. assertMaster(newMasterNode, nodes);
// 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);
}
});
assertThat(masters.size(), equalTo(2)); assertThat(masters.size(), equalTo(2));
for (Map.Entry<String, List<Tuple<String, String>>> entry : masters.entrySet()) { for (Map.Entry<String, List<Tuple<String, String>>> entry : masters.entrySet()) {
@ -1366,14 +1358,16 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase {
}, 10, TimeUnit.SECONDS); }, 10, TimeUnit.SECONDS);
} }
private void assertMaster(String masterNode, List<String> nodes) { private void assertMaster(String masterNode, List<String> nodes) throws Exception {
for (String node : nodes) { assertBusy(() -> {
ClusterState state = getNodeClusterState(node); for (String node : nodes) {
String failMsgSuffix = "cluster_state:\n" + state.prettyPrint(); ClusterState state = getNodeClusterState(node);
assertThat("wrong node count on [" + node + "]. " + failMsgSuffix, state.nodes().getSize(), equalTo(nodes.size())); String failMsgSuffix = "cluster_state:\n" + state.prettyPrint();
String otherMasterNodeName = state.nodes().getMasterNode() != null ? state.nodes().getMasterNode().getName() : null; assertThat("wrong node count on [" + node + "]. " + failMsgSuffix, state.nodes().getSize(), equalTo(nodes.size()));
assertThat("wrong master on node [" + node + "]. " + failMsgSuffix, otherMasterNodeName, equalTo(masterNode)); 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<String> nodes) throws InterruptedException { private void assertDiscoveryCompleted(List<String> nodes) throws InterruptedException {