Use a http server to hold the port busy before the real test. (#3283)

* Use a http server to hold the port busy before the real test.

Signed-off-by: Rodrigo Salado Anaya <rodrigo.salado.anaya@gmail.com>

* Use the onSuccess / onFailure lambdas to improve the test

Signed-off-by: Rodrigo Salado Anaya <rodrigo.salado.anaya@gmail.com>

* Following the recommendation of use AsyncTestBase.onFailure()

Signed-off-by: Rodrigo Salado Anaya <rodrigo.salado.anaya@gmail.com>

* Use onSuccess to check the port in the http server

Signed-off-by: Rodrigo Salado Anaya <rodrigo.salado.anaya@gmail.com>

* Use a finally block to close the http server

Signed-off-by: Rodrigo Salado Anaya <rodrigo.salado.anaya@gmail.com>
This commit is contained in:
Rodrigo Salado Anaya
2020-02-20 02:58:21 -06:00
committed by GitHub
parent 4037b11287
commit b7c04644fa

View File

@@ -903,18 +903,21 @@ public class NetTest extends VertxTestBase {
@Test
public void testListenInvalidPort() {
/* Port 80 is free to use by any application on Windows, so this test fails. */
Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows"));
server.close();
server = vertx.createNetServer(new NetServerOptions().setPort(80));
server.connectHandler((netSocket) -> {
}).listen(ar -> {
assertTrue(ar.failed());
assertFalse(ar.succeeded());
assertNotNull(ar.cause());
testComplete();
});
await();
final int port = 9090;
final HttpServer httpServer = vertx.createHttpServer();
try {
httpServer.requestHandler(ignore -> {})
.listen(port, onSuccess(s ->
vertx.createNetServer()
.connectHandler(ignore -> {})
.listen(port, onFailure(error -> {
assertNotNull(error);
testComplete();
}))));
await();
} finally {
httpServer.close();
}
}
@Test