From 64aa4d5348c0289fe747352a221eb2f0a8abd1ae Mon Sep 17 00:00:00 2001 From: Artem Vozhdayenko Date: Fri, 8 Jul 2022 18:26:50 +0300 Subject: [PATCH] GH-3666: Revise TcpNioConnectionTests Fixes: https://github.com/spring-projects/spring-integration/issues/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 --- .../ip/tcp/connection/TcpNioConnectionTests.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java index b36fc71509..4a996c2fa4 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Method; import java.net.ConnectException; +import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketTimeoutException; @@ -63,7 +64,6 @@ import javax.net.SocketFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; @@ -839,13 +839,11 @@ public class TcpNioConnectionTests { } @Test - @Disabled("Until https://github.com/spring-projects/spring-integration/issues/3666") public void testMultiAccept() throws InterruptedException, IOException { testMulti(true); } @Test - @Disabled("Until https://github.com/spring-projects/spring-integration/issues/3666") public void testNoMultiAccept() throws InterruptedException, IOException { testMulti(false); } @@ -874,8 +872,9 @@ public class TcpNioConnectionTests { server.afterPropertiesSet(); server.start(); assertThat(serverReadyLatch.await(10, TimeUnit.SECONDS)).isTrue(); + InetAddress localHost = InetAddress.getLocalHost(); for (int i = 0; i < 10; i++) { - Socket socket = SocketFactory.getDefault().createSocket("localhost", server.getPort()); + Socket socket = SocketFactory.getDefault().createSocket(localHost, server.getPort()); socket.getOutputStream().write("foo\r\n".getBytes()); sockets.add(socket); }