Test: ZenFaultDetectionTests.testNodesFaultDetectionConnectOnDisconnect should account for initial ping
There was a race condition in the test in the case where the nodes fault detection would manage to send and initial ping, followed by 2 attempts before the target service was disconnected.
This commit is contained in:
parent
cb0d462aa0
commit
c077683248
|
@ -131,17 +131,31 @@ public class ZenFaultDetectionTests extends ElasticsearchTestCase {
|
|||
public void testNodesFaultDetectionConnectOnDisconnect() throws InterruptedException {
|
||||
ImmutableSettings.Builder settings = ImmutableSettings.builder();
|
||||
boolean shouldRetry = randomBoolean();
|
||||
// make sure we don't ping
|
||||
// make sure we don't ping again after the initial ping
|
||||
settings.put(FaultDetection.SETTING_CONNECT_ON_NETWORK_DISCONNECT, shouldRetry)
|
||||
.put(FaultDetection.SETTING_PING_INTERVAL, "5m");
|
||||
ClusterState clusterState = ClusterState.builder(new ClusterName("test")).nodes(buildNodesForA(true)).build();
|
||||
NodesFaultDetection nodesFD = new NodesFaultDetection(settings.build(), threadPool, serviceA, clusterState.getClusterName());
|
||||
nodesFD.setLocalNode(clusterState.nodes().localNode());
|
||||
nodesFD.updateNodesAndPing(clusterState);
|
||||
NodesFaultDetection nodesFDA = new NodesFaultDetection(settings.build(), threadPool, serviceA, clusterState.getClusterName());
|
||||
nodesFDA.setLocalNode(nodeA);
|
||||
NodesFaultDetection nodesFDB = new NodesFaultDetection(settings.build(), threadPool, serviceB, clusterState.getClusterName());
|
||||
nodesFDB.setLocalNode(nodeB);
|
||||
final CountDownLatch pingSent = new CountDownLatch(1);
|
||||
nodesFDB.addListener(new NodesFaultDetection.Listener() {
|
||||
@Override
|
||||
public void onPingReceived(NodesFaultDetection.PingRequest pingRequest) {
|
||||
pingSent.countDown();
|
||||
}
|
||||
});
|
||||
nodesFDA.updateNodesAndPing(clusterState);
|
||||
|
||||
// wait for the first ping to go out, so we will really respond to a disconnect event rather then
|
||||
// the ping failing
|
||||
pingSent.await(30, TimeUnit.SECONDS);
|
||||
|
||||
final String[] failureReason = new String[1];
|
||||
final DiscoveryNode[] failureNode = new DiscoveryNode[1];
|
||||
final CountDownLatch notified = new CountDownLatch(1);
|
||||
nodesFD.addListener(new NodesFaultDetection.Listener() {
|
||||
nodesFDA.addListener(new NodesFaultDetection.Listener() {
|
||||
@Override
|
||||
public void onNodeFailure(DiscoveryNode node, String reason) {
|
||||
failureNode[0] = node;
|
||||
|
|
Loading…
Reference in New Issue