diff --git a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/QoSHandlerTest.java b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/QoSHandlerTest.java index f52761bfb9c..2e4392bbcb4 100644 --- a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/QoSHandlerTest.java +++ b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/QoSHandlerTest.java @@ -17,6 +17,7 @@ import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.Vector; +import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; import java.util.stream.IntStream; @@ -436,31 +437,35 @@ public class QoSHandlerTest int parallelism = 8; Vector statusCodes = new Vector<>(); // due to synchronized List - IntStream.range(0, parallelism).parallel().forEach(i -> + ForkJoinPool fjp = new ForkJoinPool(parallelism); + try { - try (LocalConnector.LocalEndPoint endPoint = connector.executeRequest(""" - GET /%d HTTP/1.1 - Host: localhost + fjp.submit(() -> IntStream.range(0, parallelism).parallel().forEach(i -> + { + try (LocalConnector.LocalEndPoint endPoint = connector.executeRequest(""" + GET /%d HTTP/1.1 + Host: localhost - """.formatted(i))) - { - String text = endPoint.getResponse(false, parallelism * delay * 5, TimeUnit.MILLISECONDS); - HttpTester.Response response = HttpTester.parseResponse(text); - statusCodes.add(response.getStatus()); - } - catch (Exception x) - { - fail(x); - } - }); - - await().atMost(5, TimeUnit.SECONDS).until(statusCodes::size, is(8)); - // expectation is that - // 2 requests will be handled straight away - // 2 will be suspended and eventually handled - // 4 will hit the max suspended request limit - assertEquals(4, statusCodes.stream().filter(sc -> sc == HttpStatus.OK_200).count()); - assertEquals(4, statusCodes.stream().filter(sc -> sc == HttpStatus.SERVICE_UNAVAILABLE_503).count()); + """.formatted(i))) { + String text = endPoint.getResponse(false, parallelism * delay * 5, TimeUnit.MILLISECONDS); + HttpTester.Response response = HttpTester.parseResponse(text); + statusCodes.add(response.getStatus()); + } catch (Exception x) { + fail(x); + } + })); + await().atMost(5, TimeUnit.SECONDS).until(statusCodes::size, is(8)); + // expectation is that + // 2 requests will be handled straight away + // 2 will be suspended and eventually handled + // 4 will hit the max suspended request limit + assertEquals(4, statusCodes.stream().filter(sc -> sc == HttpStatus.OK_200).count()); + assertEquals(4, statusCodes.stream().filter(sc -> sc == HttpStatus.SERVICE_UNAVAILABLE_503).count()); + } + finally + { + fjp.shutdown(); + } } }