From 2b00ecb5b5a3ab03070f3d7aa9ec25998ca82d94 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 2 Mar 2015 15:30:39 +0100 Subject: [PATCH] Test: use assertBusy to fix timing issue --- .../DiscoveryWithServiceDisruptionsTests.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsTests.java b/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsTests.java index 33f3989e84c65..2a983ad812c98 100644 --- a/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsTests.java +++ b/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsTests.java @@ -598,7 +598,7 @@ public void testStaleMasterNotHijackingMajority() throws Exception { // TODO: on mac OS multicast threads are shared between nodes and we therefore we can't simulate GC and stop pinging for just one node // find a way to block thread creation in the generic thread pool to avoid this. // 3 node cluster with unicast discovery and minimum_master_nodes set to 2: - List nodes = startUnicastCluster(3, null, 2); + final List nodes = startUnicastCluster(3, null, 2); // Save the current master node as old master node, because that node will get frozen final String oldMasterNode = internalCluster().getMasterName(); @@ -666,7 +666,15 @@ public void onFailure(String source, Throwable t) { // Make sure that the end state is consistent on all nodes: assertDiscoveryCompleted(nodes); - assertMaster(newMasterNode, nodes); + // Use assertBusy(...) because the unfrozen node may take a while to actually join the cluster. + // The assertDiscoveryCompleted(...) can't know if the joining has finished or still needs to begin. + // (the discovery only kicks in when unfrozen node steps down, which isn't immediately) + assertBusy(new Runnable() { + @Override + public void run() { + assertMaster(newMasterNode, nodes); + } + }); assertThat(masters.size(), equalTo(2));