testMockFailToSendNoConnectRule should wait for connection close to bubble up and disconnect the node

#25521 changed channel closing to be handled async on anything but transport stop. This means it may take a while before
calling `connection.close()` and the node being removed from the `connectedNodes` list (but the connection is immediately unusuable).

Fixes #25686
This commit is contained in:
Boaz Leskes 2017-07-15 09:28:17 +02:00
parent 072402463b
commit a6bea1bf97
1 changed files with 5 additions and 3 deletions

View File

@ -30,7 +30,6 @@ import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListenerResponseHandler; import org.elasticsearch.action.ActionListenerResponseHandler;
import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
@ -80,7 +79,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collector;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
@ -1418,7 +1416,7 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase {
assertThat(version0Response.value1, equalTo(1)); assertThat(version0Response.value1, equalTo(1));
} }
public void testMockFailToSendNoConnectRule() throws IOException { public void testMockFailToSendNoConnectRule() throws Exception {
serviceA.registerRequestHandler("sayHello", StringMessageRequest::new, ThreadPool.Names.GENERIC, serviceA.registerRequestHandler("sayHello", StringMessageRequest::new, ThreadPool.Names.GENERIC,
(request, channel) -> { (request, channel) -> {
assertThat("moshe", equalTo(request.message)); assertThat("moshe", equalTo(request.message));
@ -1461,6 +1459,10 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase {
assertThat(((ConnectTransportException)cause).node(), equalTo(nodeA)); assertThat(((ConnectTransportException)cause).node(), equalTo(nodeA));
} }
// wait for the transport to process the sending failure and disconnect from node
assertBusy(() -> assertFalse(serviceB.nodeConnected(nodeA)));
// now try to connect again and see that it fails
try { try {
serviceB.connectToNode(nodeA); serviceB.connectToNode(nodeA);
fail("exception should be thrown"); fail("exception should be thrown");