Skip to content

Commit

Permalink
Make test non racy
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed May 8, 2023
1 parent c100520 commit f30471c
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/test/java/io/vertx/ext/stomp/impl/WebSocketBridgeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@

import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.WebSocket;
import io.vertx.core.http.WebSocketConnectOptions;
import io.vertx.core.http.WebSocketFrame;
import io.vertx.core.http.*;
import io.vertx.ext.bridge.PermittedOptions;
import io.vertx.ext.stomp.*;
import io.vertx.ext.stomp.utils.Headers;
Expand Down Expand Up @@ -329,19 +325,22 @@ public void testPingFromServer() {

await().atMost(10, TimeUnit.SECONDS).until(() -> client.get() != null);

vertx.createHttpClient().webSocket(options).onComplete(ar -> {
if (ar.succeeded()) {
WebSocket ws = ar.result();
socket.set(ws);
ws.exceptionHandler(error::set)
.handler(buffer -> {
vertx.setTimer(1000, id -> {
flag.set(true);
});
})
.write(new Frame(Command.CONNECT, Headers.create("accept-version", "1.2,1.1,1.0",
"heart-beat", "100,0"), null).toBuffer());
}
HttpClient wsClient = vertx.createHttpClient();
vertx.runOnContext(v -> {
wsClient.webSocket(options).onComplete(ar -> {
if (ar.succeeded()) {
WebSocket ws = ar.result();
socket.set(ws);
ws.exceptionHandler(error::set)
.handler(buffer -> {
vertx.setTimer(1000, id -> {
flag.set(true);
});
})
.write(new Frame(Command.CONNECT, Headers.create("accept-version", "1.2,1.1,1.0",
"heart-beat", "100,0"), null).toBuffer());
}
});
});

await().atMost(10, TimeUnit.SECONDS).until(() -> error.get() == null && flag.get() != null);
Expand Down

0 comments on commit f30471c

Please sign in to comment.