Skip to content

Commit 2452c4e

Browse files
committed
Fix intermittent failure in ForwardedTest (#2918)
Fixes #2916 Sometimes ForwardedTest.testXForwardMissingHostHeader would time out on Windows, having the fabricated connection closed. This was probably due to the NetClient, scoped to the test method, being eagerly cleanup by the JVM. Signed-off-by: Thomas Segismont <[email protected]>
1 parent 8aa3264 commit 2452c4e

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

vertx-web/src/test/java/io/vertx/ext/web/tests/ForwardedTest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,23 @@
2525
import io.vertx.junit5.Checkpoint;
2626
import io.vertx.test.core.TestUtils;
2727
import static org.junit.jupiter.api.Assertions.*;
28+
29+
import org.junit.jupiter.api.AfterEach;
2830
import org.junit.jupiter.api.Test;
2931

3032
import static io.vertx.ext.web.AllowForwardHeaders.*;
3133

3234
public class ForwardedTest extends WebTestBase {
3335

36+
private NetClient netClient;
37+
38+
@AfterEach
39+
void cleanup() {
40+
if (netClient != null) {
41+
netClient.close().await();
42+
}
43+
}
44+
3445
@Test
3546
public void testXForwardSSL() {
3647
router.allowForward(ALL).route("/").handler(rc -> {
@@ -432,14 +443,12 @@ public void testMissingHostHeader(Checkpoint done) {
432443
}
433444

434445
private void testMissingHostHeader(Checkpoint done, Route route) {
435-
436446
route.handler(rc -> {
437447
assertNull(rc.request().authority());
438448
rc.end();
439449
});
440-
441-
NetClient tcpClient = vertx.createNetClient();
442-
tcpClient.connect(8080, "localhost").onComplete(TestUtils.onSuccess(so -> {
450+
netClient = vertx.createNetClient();
451+
netClient.connect(8080, "localhost").onComplete(TestUtils.onSuccess(so -> {
443452
so.write("GET / HTTP/1.1\r\n\r\n");
444453
so.handler(buff -> {
445454
done.flag();

0 commit comments

Comments
 (0)