mirror of
https://github.com/jlengrand/vert.x.git
synced 2026-03-10 08:51:19 +00:00
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:
committed by
Julien Viet
parent
763b9b5594
commit
adcd6d31af
@@ -982,18 +982,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
|
||||
|
||||
Reference in New Issue
Block a user