Issue #2536 - Broken ClientConnectTest.testConnectionTimeout_Concurrent.

Updated the code to show more information when it fails.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2018-05-16 14:25:03 +02:00
parent 4cc8f4dcf6
commit 804b770581
1 changed files with 13 additions and 16 deletions

View File

@ -18,14 +18,6 @@
package org.eclipse.jetty.websocket.client;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@ -60,6 +52,13 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Various connect condition testing
*/
@ -72,15 +71,15 @@ public class ClientConnectTest
private WebSocketClient client;
@SuppressWarnings("unchecked")
private <E extends Throwable> E assertExpectedError(ExecutionException e, JettyTrackingSocket wsocket, Matcher<Throwable> errorMatcher) throws IOException
private <E extends Throwable> E assertExpectedError(ExecutionException e, JettyTrackingSocket wsocket, Matcher<Throwable> errorMatcher)
{
// Validate thrown cause
Throwable cause = e.getCause();
Assert.assertThat("ExecutionException.cause",cause,errorMatcher);
Assert.assertThat("ExecutionException.cause "+cause,cause,errorMatcher);
// Validate websocket captured cause
Assert.assertThat("Error Queue Length",wsocket.errorQueue.size(),greaterThanOrEqualTo(1));
Assert.assertThat("Error Queue Length "+wsocket.errorQueue,wsocket.errorQueue.size(),greaterThanOrEqualTo(1));
Throwable capcause = wsocket.errorQueue.poll();
Assert.assertThat("Error Queue[0]",capcause,notNullValue());
Assert.assertThat("Error Queue[0]",capcause,errorMatcher);
@ -462,7 +461,7 @@ public class ClientConnectTest
}
}
@Test(expected = TimeoutException.class)
@Test
public void testConnectionTimeout_Concurrent() throws Exception
{
JettyTrackingSocket wsocket = new JettyTrackingSocket();
@ -482,13 +481,11 @@ public class ClientConnectTest
// The attempt to get upgrade response future should throw error
try
{
future.get(3, TimeUnit.SECONDS);
future.get(1, TimeUnit.SECONDS);
Assert.fail("Expected ExecutionException -> TimeoutException");
}
catch (ExecutionException e)
catch (TimeoutException expected)
{
// Expected path - java.net.ConnectException ?
assertExpectedError(e, wsocket, instanceOf(ConnectException.class));
}
}
}