Skip to content

Commit

Permalink
Improve HttpTest#testConcurrentWrite
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Dec 12, 2023
1 parent 1884599 commit e97c825
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/test/java/io/vertx/core/http/HttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6677,7 +6677,6 @@ public void testInvalidPort() {
@Test
public void testConcurrentWrites() throws Exception {
waitFor(1);
ExecutorService executor = Executors.newFixedThreadPool(1);
AtomicReference<String> received = new AtomicReference<>();
server.requestHandler(req -> req.body()
.onSuccess(buffer -> {
Expand All @@ -6688,23 +6687,20 @@ public void testConcurrentWrites() throws Exception {
client.close();
client = vertx.createHttpClient(createBaseClientOptions());
client.request(requestOptions)
.compose(req -> {
req.setChunked(true);
Future<Void> future = req.sendHead();
if (this instanceof Http1xTest) {
while (!future.isComplete()) { } // Wait for the header to be sent.
}
AtomicBoolean latch = new AtomicBoolean(false);
executor.submit(() -> {
req.write("msg1");
latch.set(true); // Release Event-loop thread
});
while (!latch.get()) { } // Active wait for the event to be published
req.write("msg2");
req.end();
return req.response();
})
.onComplete(onSuccess(resp -> complete()));
.compose(req -> req.setChunked(true).sendHead().compose(v -> {
AtomicBoolean latch = new AtomicBoolean(false);
new Thread(() -> {
req.write("msg1");
latch.set(true); // Release Event-loop thread
}).start();
// Active wait for the event to be published
while (!latch.get()) {
}
req.write("msg2");
req.end();
return req.response();
}))
.onComplete(onSuccess(resp -> complete()));
await();
assertEquals("msg1msg2", received.get());
}
Expand Down

0 comments on commit e97c825

Please sign in to comment.