public Socket awaitConnection() throws InterruptedException {
    return awaitConnection(Long.MAX_VALUE);
  }
@Test
  public void testConnectEventually() throws Exception {
    serverSocket.close();

    Thread thread = new Thread();
    thread.start();
    Socket socket = connector.awaitConnection(2 * DELAY);
    assertNull(socket);
    Exception lastException = exceptionHandler.awaitConnectionFailed(DELAY);
    assertTrue(lastException instanceof ConnectException);
    assertTrue(thread.isAlive());

    // now rebind to the same local address
    SocketAddress address = serverSocket.getLocalSocketAddress();
    serverSocket = new ServerSocket();
    serverSocket.setReuseAddress(true);
    serverSocket.bind(address);

    // now we should be able to connect
    socket = connector.awaitConnection(2 * DELAY);
    assertNotNull(socket);
    thread.join(DELAY);
    assertFalse(thread.isAlive());
    socket.close();
  }