Test: fix testStaleMasterNotHijackingMajority by waiting for the old master node to step down.
It may take some time for the old master node to step down anf for it to rejoin and that all nodes have it in the nodes list. By waiting for the old master node to have stepped down, we can again rely on assertDiscoveryCompleted() to make sure that it has joined.
This commit is contained in:
parent
21e246f6a3
commit
e559471948
|
@ -632,6 +632,16 @@ public class DiscoveryWithServiceDisruptionsTests extends ElasticsearchIntegrati
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final CountDownLatch oldMasterNodeSteppedDown = new CountDownLatch(1);
|
||||||
|
internalCluster().getInstance(ClusterService.class, oldMasterNode).add(new ClusterStateListener() {
|
||||||
|
@Override
|
||||||
|
public void clusterChanged(ClusterChangedEvent event) {
|
||||||
|
if (event.state().nodes().masterNodeId() == null) {
|
||||||
|
oldMasterNodeSteppedDown.countDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
internalCluster().setDisruptionScheme(masterNodeDisruption);
|
internalCluster().setDisruptionScheme(masterNodeDisruption);
|
||||||
logger.info("freezing node [{}]", oldMasterNode);
|
logger.info("freezing node [{}]", oldMasterNode);
|
||||||
masterNodeDisruption.startDisrupting();
|
masterNodeDisruption.startDisrupting();
|
||||||
|
@ -664,11 +674,11 @@ public class DiscoveryWithServiceDisruptionsTests extends ElasticsearchIntegrati
|
||||||
logger.info("Unfreeze node [{}]", oldMasterNode);
|
logger.info("Unfreeze node [{}]", oldMasterNode);
|
||||||
masterNodeDisruption.stopDisrupting();
|
masterNodeDisruption.stopDisrupting();
|
||||||
|
|
||||||
|
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.
|
// 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 assertDiscoveryCompleted(...) can't know if all nodes have the old master node in all of the local cluster states
|
||||||
// (the discovery only kicks in when unfrozen node steps down, which isn't immediately)
|
|
||||||
assertBusy(new Runnable() {
|
assertBusy(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -685,7 +695,7 @@ public class DiscoveryWithServiceDisruptionsTests extends ElasticsearchIntegrati
|
||||||
assertThat("[" + nodeName + "] First transition's previous master should be [null]", recordedMasterTransition.get(0).v1(), equalTo(oldMasterNode));
|
assertThat("[" + nodeName + "] First transition's previous master should be [null]", recordedMasterTransition.get(0).v1(), equalTo(oldMasterNode));
|
||||||
assertThat("[" + nodeName + "] First transition's current master should be [" + newMasterNode + "]", recordedMasterTransition.get(0).v2(), nullValue());
|
assertThat("[" + nodeName + "] First transition's current master should be [" + newMasterNode + "]", recordedMasterTransition.get(0).v2(), nullValue());
|
||||||
assertThat("[" + nodeName + "] Second transition's previous master should be [null]", recordedMasterTransition.get(1).v1(), nullValue());
|
assertThat("[" + nodeName + "] Second transition's previous master should be [null]", recordedMasterTransition.get(1).v1(), nullValue());
|
||||||
assertThat("[" + nodeName + "] jSecond transition's current master should be [" + newMasterNode + "]", recordedMasterTransition.get(1).v2(), equalTo(newMasterNode));
|
assertThat("[" + nodeName + "] Second transition's current master should be [" + newMasterNode + "]", recordedMasterTransition.get(1).v2(), equalTo(newMasterNode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue