Skip to content

Commit

Permalink
GH-3666: Revise TcpNioConnectionTests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
oxcafedead committed Jul 8, 2022
1 parent 2e219ff commit 64aa4d5
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand Down Expand Up @@ -63,7 +64,6 @@

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;
Expand Down Expand Up @@ -839,13 +839,11 @@ public void testNoDelayOnClose() throws Exception {
}

@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);
}
Expand Down Expand Up @@ -874,8 +872,9 @@ private void testMulti(boolean multiAccept) throws InterruptedException, IOExcep
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);
}
Expand Down

0 comments on commit 64aa4d5

Please sign in to comment.