Skip to content

Commit

Permalink
Improve Http1xTest#testHttpServerWithIdleTimeoutSendChunkedFile that …
Browse files Browse the repository at this point in the history
…needs to probe the actual time to send a chunked file to pass reliably independantly of the test env.
  • Loading branch information
vietj committed Sep 22, 2024
1 parent ecd187c commit 64f1a71
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions vertx-core/src/test/java/io/vertx/tests/http/Http1xTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4859,21 +4859,34 @@ public void start(Promise<Void> startFuture) {
public void testHttpServerWithIdleTimeoutSendChunkedFile() throws Exception {
// Does not pass reliably in CI (timeout)
Assume.assumeTrue(!vertx.isNativeTransportEnabled() && !Utils.isWindows());
int expected = 64 * 1024 * 1024; // We estimate this will take more than 200ms to transfer with a 1ms pause in chunks
File sent = TestUtils.tmpFile(".dat", expected);
server.close();
int expected = 32 * 1024 * 1024; // We estimate this will take more than 200ms to transfer with a 1ms pause in chunks
File file = TestUtils.tmpFile(".dat", expected);
int delay = retrieveFileFromServer(file, createBaseServerOptions());
int timeout = delay / 2;
delay = retrieveFileFromServer(file, createBaseServerOptions().setIdleTimeout(timeout).setIdleTimeoutUnit(TimeUnit.MILLISECONDS));
assertTrue(delay > timeout);
}

private int retrieveFileFromServer(File file, HttpServerOptions options) throws Exception {
server.close().await();
server = vertx
.createHttpServer(createBaseServerOptions().setIdleTimeout(1000).setIdleTimeoutUnit(TimeUnit.MILLISECONDS))
.createHttpServer(options)
.requestHandler(
req -> {
req.response().sendFile(sent.getAbsolutePath());
req.response().sendFile(file.getAbsolutePath());
});
startServer(testAddress);
client.request(requestOptions)
.onComplete(onSuccess(req -> {
req.send().onComplete(onSuccess(resp -> {
long now = System.currentTimeMillis();
int[] length = {0};
long now = System.currentTimeMillis();
Integer len = getFile().await();
assertEquals((int)len, file.length());
return (int) (System.currentTimeMillis() - now);
}

private Future<Integer> getFile() {
int[] length = {0};
return client.request(requestOptions)
.compose(req -> req.send()
.compose(resp -> {
resp.handler(buff -> {
length[0] += buff.length();
resp.pause();
Expand All @@ -4882,14 +4895,9 @@ public void testHttpServerWithIdleTimeoutSendChunkedFile() throws Exception {
});
});
resp.exceptionHandler(this::fail);
resp.endHandler(v -> {
assertEquals(expected, length[0]);
assertTrue(System.currentTimeMillis() - now > 1000);
testComplete();
});
}));
}));
await();
return resp.end();
}))
.map(v -> length[0]);
}

@Test
Expand Down

0 comments on commit 64f1a71

Please sign in to comment.