Fixing http2-client test quirk when

This commit is contained in:
Joakim Erdfelt 2015-02-12 14:42:02 -07:00
parent 0677735550
commit 7811c10727
2 changed files with 18 additions and 8 deletions

View File

@ -116,7 +116,13 @@ public class AbstractTest
@After
public void dispose() throws Exception
{
client.stop();
server.stop();
if (client != null)
{
client.stop();
}
if (server != null)
{
server.stop();
}
}
}

View File

@ -62,6 +62,8 @@ public class ConnectTimeoutTest extends AbstractTest
private void assumeConnectTimeout(String host, int port, int connectTimeout) throws IOException
{
boolean socketTimeout = false;
try (Socket socket = new Socket())
{
// Try to connect to a private address in the 10.x.y.z range.
@ -69,18 +71,20 @@ public class ConnectTimeoutTest extends AbstractTest
// connect to them will hang the connection attempt, which is
// what we want to simulate in this test.
socket.connect(new InetSocketAddress(host, port), connectTimeout);
// Abort the test if we can connect.
Assume.assumeTrue(false);
}
catch (SocketTimeoutException x)
{
// Expected timeout during connect, continue the test.
Assume.assumeTrue(true);
// We expect a timeout during connect, allow test to continue.
socketTimeout = true;
}
catch (Throwable x)
{
// Abort if any other exception happens.
Assume.assumeTrue(false);
// Dump stacktrace when there is an unexpected test failure
// Useful when debugging
x.printStackTrace(System.err);
}
// Abort the test if we can connect.
Assume.assumeTrue("Should have seen connect timeout",socketTimeout);
}
}