Skip to content

Commit

Permalink
reduce system timing sensitivity in SocketConnectorBaseTest
Browse files Browse the repository at this point in the history
Now using a larger delay tolerance and additional Thread.join calls to
give the connector thread time to exit before testing assertions that
it did exit properly.
  • Loading branch information
ceharris committed Apr 4, 2013
1 parent f9d9a6c commit e9c22de
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public class SocketConnectorBaseTest {

private static final int DELAY = 250;
private static final int DELAY = 1000;

private MockExceptionHandler exceptionHandler = new MockExceptionHandler();

Expand Down Expand Up @@ -65,6 +65,7 @@ public void testConnect() throws Exception {
thread.start();
Socket socket = connector.awaitConnection(2 * DELAY);
assertNotNull(socket);
thread.join(DELAY);
assertFalse(thread.isAlive());
socket.close();
}
Expand All @@ -79,7 +80,7 @@ public void testConnectionFails() throws Exception {
assertTrue(exceptionHandler.getLastException() instanceof ConnectException);
assertTrue(thread.isAlive());
thread.interrupt();
thread.join(1000);
thread.join(DELAY);
assertFalse(thread.isAlive());
assertTrue(exceptionHandler.getLastException() instanceof InterruptedException);
}
Expand All @@ -104,6 +105,7 @@ public void testConnectEventually() throws Exception {
// now we should be able to connect
socket = connector.awaitConnection(2 * DELAY);
assertNotNull(socket);
thread.join(DELAY);
assertFalse(thread.isAlive());
socket.close();
}
Expand Down

0 comments on commit e9c22de

Please sign in to comment.