Skip to content

Commit 6f1e3fe

Browse files
committed
Improve Http3ContextTest
Modernize test a bit. Fix racy test relying on unconfined future composition.
1 parent 0bd68b2 commit 6f1e3fe

1 file changed

Lines changed: 23 additions & 28 deletions

File tree

vertx-core/src/test/java/io/vertx/tests/http/http3/Http3ContextTest.java

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,37 @@
1919
import io.vertx.core.internal.VertxInternal;
2020
import io.vertx.core.net.ClientSSLOptions;
2121
import io.vertx.core.net.ServerSSLOptions;
22-
import io.vertx.test.core.VertxTestBase;
22+
import io.vertx.test.core.TestUtils;
23+
import io.vertx.test.core.VertxTestBase2;
2324
import io.vertx.test.tls.Cert;
2425
import io.vertx.test.tls.Trust;
25-
import org.junit.Assert;
26+
import org.junit.After;
27+
import org.junit.Before;
2628
import org.junit.Test;
2729

28-
public class Http3ContextTest extends VertxTestBase {
30+
import static org.junit.Assert.*;
31+
32+
public class Http3ContextTest extends VertxTestBase2 {
2933

3034
private HttpServer server;
3135
private HttpClientConfig clientConfig;
3236
private HttpClientAgent client;
3337

3438
public Http3ContextTest() {
35-
super(ReportMode.FORBIDDEN);
3639
}
3740

38-
@Override
41+
@Before
3942
public void setUp() throws Exception {
40-
super.setUp();
4143
clientConfig = new HttpClientConfig();
4244
clientConfig.setVersions(HttpVersion.HTTP_3);
4345
server = vertx.createHttpServer(new HttpServerConfig().setVersions(HttpVersion.HTTP_3), new ServerSSLOptions().setKeyCertOptions(Cert.SERVER_JKS.get()));
4446
client = vertx.createHttpClient(clientConfig, new ClientSSLOptions().setTrustOptions(Trust.SERVER_JKS.get()));
4547
}
4648

47-
@Override
48-
protected void tearDown() throws Exception {
49+
@After
50+
public void tearDown() throws Exception {
4951
server.close().await();
5052
client.close().await();
51-
super.tearDown();
5253
}
5354

5455
@Test
@@ -65,17 +66,11 @@ private void testServerRequestContext(ThreadingModel threadingModel) {
6566

6667
server.requestHandler(req -> {
6768
Context ctx = Vertx.currentContext();
68-
Assert.assertEquals(threadingModel, ctx.threadingModel());
69+
assertEquals(threadingModel, ctx.threadingModel());
6970
assertIsDuplicate(req, ctx);
70-
Buffer body = Buffer.buffer();
71-
req.handler(chunk -> {
72-
Assert.assertSame(ctx, Vertx.currentContext());
73-
body.appendBuffer(chunk);
74-
});
75-
req.endHandler(v -> {
76-
Assert.assertSame(ctx, Vertx.currentContext());
71+
req.body().onComplete(TestUtils.onSuccess(body -> {
7772
req.response().end(body);
78-
});
73+
}));
7974
});
8075

8176
ContextInternal serverCtx = ((VertxInternal) vertx).createContext(threadingModel);
@@ -85,10 +80,10 @@ private void testServerRequestContext(ThreadingModel threadingModel) {
8580
.compose(request -> request
8681
.send(Buffer.buffer("payload"))
8782
.expecting(HttpResponseExpectation.SC_OK)
88-
)
89-
.compose(HttpClientResponse::body).await();
83+
.compose(HttpClientResponse::body)
84+
).await();
9085

91-
Assert.assertEquals("payload", response.toString());
86+
assertEquals("payload", response.toString());
9287
}
9388

9489
@Test
@@ -115,28 +110,28 @@ public void testClientRequestContext(ThreadingModel threadingModel) {
115110
HttpClientRequest request1 = Future.<HttpClientRequest>future(p -> connectionCtx.runOnContext(v -> client.request(HttpMethod.POST, 8443, "localhost", "/").onComplete(p))).await();
116111

117112
Buffer body = request1.send().compose(response -> {
118-
Assert.assertSame(connectionCtx, Vertx.currentContext());
113+
assertSame(connectionCtx, Vertx.currentContext());
119114
return response.body();
120115
}).await();
121-
Assert.assertEquals("Hello World", body.toString());
116+
assertEquals("Hello World", body.toString());
122117

123118
HttpClientRequest request2 = Future.<HttpClientRequest>future(p -> streamCtx.runOnContext(v -> client.request(HttpMethod.POST, 8443, "localhost", "/").onComplete(p))).await();
124119
body = request2.send().compose(response -> {
125-
Assert.assertSame(streamCtx, Vertx.currentContext());
120+
assertSame(streamCtx, Vertx.currentContext());
126121
return response.body();
127122
}).await();
128-
Assert.assertEquals("Hello World", body.toString());
123+
assertEquals("Hello World", body.toString());
129124

130-
Assert.assertSame(request1.connection(), request2.connection());
125+
assertSame(request1.connection(), request2.connection());
131126
}
132127

133128
private void assertIsDuplicate(HttpServerRequest request, Context context) {
134129
assertIsDuplicate(request, (ContextInternal)context);
135130
}
136131

137132
private void assertIsDuplicate(HttpServerRequest request, ContextInternal context) {
138-
Assert.assertTrue(context.isDuplicate());
133+
assertTrue(context.isDuplicate());
139134
HttpServerConnection connection = (HttpServerConnection) request.connection();
140-
Assert.assertSame(connection.context(), context.unwrap());
135+
assertSame(connection.context(), context.unwrap());
141136
}
142137
}

0 commit comments

Comments
 (0)