Skip to content

Commit 6120465

Browse files
committed
Fix incorrect test
1 parent 85082f5 commit 6120465

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/test/java/io/vertx/tests/interceptors/WebSocketInterceptorTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import io.vertx.core.Future;
44
import io.vertx.core.buffer.Buffer;
5-
import io.vertx.core.http.HttpClientRequest;
6-
import io.vertx.core.http.HttpMethod;
7-
import io.vertx.core.http.ServerWebSocket;
5+
import io.vertx.core.http.*;
86
import io.vertx.core.net.SocketAddress;
97
import io.vertx.ext.unit.Async;
108
import io.vertx.ext.unit.TestContext;
@@ -49,31 +47,33 @@ private SocketAddress backend(TestContext ctx, Async async) {
4947
* @param wsHit if interceptor changes the WebSocket packet
5048
*/
5149
private void testWithInterceptor(TestContext ctx, ProxyInterceptor interceptor, boolean httpHit, boolean wsHit) {
52-
Async latch = ctx.async(4);
50+
Async latch = ctx.async(3);
5351
SocketAddress backend = backend(ctx, latch);
5452

5553
startProxy(proxy -> {
5654
proxy.origin(backend);
57-
if (interceptor != null) proxy.addInterceptor(interceptor);
55+
if (interceptor != null) {
56+
proxy.addInterceptor(interceptor);
57+
};
5858
});
5959

60-
vertx.createHttpClient().request(HttpMethod.GET, 8080, "localhost", "/http")
61-
.compose(HttpClientRequest::send)
62-
.onComplete(ctx.asyncAssertSuccess(resp -> {
63-
resp.body().onSuccess(body -> {
64-
ctx.assertEquals(body.toString().endsWith("/updated"), httpHit);
60+
HttpClientAgent httpClient = vertx.createHttpClient();
61+
WebSocketClient webSocketClient = vertx.createWebSocketClient();
62+
63+
Buffer body = httpClient
64+
.request(HttpMethod.GET, 8080, "localhost", "/http")
65+
.compose(req -> req.send()
66+
.expecting(HttpResponseExpectation.SC_OK))
67+
.compose(HttpClientResponse::body).await();
68+
ctx.assertEquals(body.toString().endsWith("/updated"), httpHit);
69+
webSocketClient.connect(8080, "localhost", "/ws")
70+
.onComplete(ctx.asyncAssertSuccess(webSocket -> {
71+
webSocket.handler(buffer -> {
72+
ctx.assertEquals(buffer.toString().endsWith("/updated"), wsHit);
6573
latch.countDown();
66-
67-
vertx.createWebSocketClient().connect(8080, "localhost", "/ws")
68-
.onComplete(ctx.asyncAssertSuccess(webSocket -> {
69-
webSocket.handler(buffer -> {
70-
ctx.assertEquals(buffer.toString().endsWith("/updated"), wsHit);
71-
latch.countDown();
72-
webSocket.close();
73-
});
74-
webSocket.write(Buffer.buffer("hello"));
75-
}));
74+
webSocket.close();
7675
});
76+
webSocket.write(Buffer.buffer("hello"));
7777
}));
7878
latch.await(5000);
7979
}

0 commit comments

Comments
 (0)