From 88fba71b4c2061d529634b1eecd482078e953219 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Sun, 19 Jan 2014 14:26:36 +0900 Subject: [PATCH] Fix occasional failure in SocketConnectionAttemptTest - Use the real host name with a firewall so that the connection attempt always takes long time on all platforms. - Fixes #2128 --- .../socket/SocketConnectionAttemptTest.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketConnectionAttemptTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketConnectionAttemptTest.java index 8ff49c4f7c..3ec6f91774 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketConnectionAttemptTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketConnectionAttemptTest.java @@ -20,6 +20,7 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandlerAdapter; import io.netty.channel.ChannelOption; import io.netty.util.internal.SystemPropertyUtil; +import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; import org.junit.Test; @@ -34,11 +35,13 @@ import static org.junit.Assume.*; public class SocketConnectionAttemptTest extends AbstractClientSocketTest { - private static final String BAD_HOST = SystemPropertyUtil.get("io.netty.testsuite.badHost", "255.255.255.0"); + private static final String BAD_HOST = SystemPropertyUtil.get("io.netty.testsuite.badHost", "netty.io"); + private static final int BAD_PORT = SystemPropertyUtil.getInt("io.netty.testsuite.badPort", 65535); static { - InternalLoggerFactory.getInstance(SocketConnectionAttemptTest.class).debug( - "-Dio.netty.testsuite.badHost: {}", BAD_HOST); + InternalLogger logger = InternalLoggerFactory.getInstance(SocketConnectionAttemptTest.class); + logger.debug("-Dio.netty.testsuite.badHost: {}", BAD_HOST); + logger.debug("-Dio.netty.testsuite.badPort: {}", BAD_PORT); } @Test(timeout = 30000) @@ -48,7 +51,7 @@ public class SocketConnectionAttemptTest extends AbstractClientSocketTest { public void testConnectTimeout(Bootstrap cb) throws Throwable { cb.handler(new ChannelHandlerAdapter()).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 2000); - ChannelFuture future = cb.connect(BAD_HOST, 8080); + ChannelFuture future = cb.connect(BAD_HOST, BAD_PORT); try { assertThat(future.await(3000), is(true)); } finally { @@ -63,7 +66,7 @@ public class SocketConnectionAttemptTest extends AbstractClientSocketTest { boolean badHostTimedOut = true; Socket socket = new Socket(); try { - socket.connect(new InetSocketAddress(BAD_HOST, 8080), 10); + socket.connect(new InetSocketAddress(BAD_HOST, BAD_PORT), 10); } catch (ConnectException e) { badHostTimedOut = false; // is thrown for no route to host when using Socket connect @@ -84,7 +87,7 @@ public class SocketConnectionAttemptTest extends AbstractClientSocketTest { public void testConnectCancellation(Bootstrap cb) throws Throwable { cb.handler(new ChannelHandlerAdapter()).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 4000); - ChannelFuture future = cb.connect(BAD_HOST, 8080); + ChannelFuture future = cb.connect(BAD_HOST, BAD_PORT); try { if (future.await(1000)) { if (future.isSuccess()) {