Skip to content

Commit 64aa4d5

Browse files
authored
GH-3666: Revise TcpNioConnectionTests
Fixes: #3666 Seems like Windows socket connect to the loopback address fails sometimes because of a bug in the implementation of OpenJDK. * Changing loopback addr with the actual IP addr seems to help. * Fix `TcpNioConnectionTests.testMultiAccept()` and `testNoMultiAccept()` to rely on the ` InetAddress.getLocalHost()` instead of `localhost` string which has to be resolved to the address yet in the testing loop
1 parent 2e219ff commit 64aa4d5

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.io.InputStream;
3535
import java.lang.reflect.Method;
3636
import java.net.ConnectException;
37+
import java.net.InetAddress;
3738
import java.net.ServerSocket;
3839
import java.net.Socket;
3940
import java.net.SocketTimeoutException;
@@ -63,7 +64,6 @@
6364

6465
import org.apache.commons.logging.Log;
6566
import org.apache.commons.logging.LogFactory;
66-
import org.junit.jupiter.api.Disabled;
6767
import org.junit.jupiter.api.Test;
6868
import org.junit.jupiter.api.TestInfo;
6969
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
@@ -839,13 +839,11 @@ public void testNoDelayOnClose() throws Exception {
839839
}
840840

841841
@Test
842-
@Disabled("Until https://github.com/spring-projects/spring-integration/issues/3666")
843842
public void testMultiAccept() throws InterruptedException, IOException {
844843
testMulti(true);
845844
}
846845

847846
@Test
848-
@Disabled("Until https://github.com/spring-projects/spring-integration/issues/3666")
849847
public void testNoMultiAccept() throws InterruptedException, IOException {
850848
testMulti(false);
851849
}
@@ -874,8 +872,9 @@ private void testMulti(boolean multiAccept) throws InterruptedException, IOExcep
874872
server.afterPropertiesSet();
875873
server.start();
876874
assertThat(serverReadyLatch.await(10, TimeUnit.SECONDS)).isTrue();
875+
InetAddress localHost = InetAddress.getLocalHost();
877876
for (int i = 0; i < 10; i++) {
878-
Socket socket = SocketFactory.getDefault().createSocket("localhost", server.getPort());
877+
Socket socket = SocketFactory.getDefault().createSocket(localHost, server.getPort());
879878
socket.getOutputStream().write("foo\r\n".getBytes());
880879
sockets.add(socket);
881880
}

0 commit comments

Comments
 (0)