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
This commit is contained in:
Trustin Lee 2014-01-19 14:26:36 +09:00
parent cab2a03760
commit 88fba71b4c

View File

@ -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()) {