From ac67ac11e9376c8fd3df0e7cb873bccae0538fe8 Mon Sep 17 00:00:00 2001 From: Andrea Marziali Date: Thu, 16 Jan 2025 13:44:55 +0100 Subject: [PATCH] use executor service --- .../trace/agent/test/base/HttpServerTest.groovy | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy b/dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy index 733886f00f1..56482d8414f 100644 --- a/dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy +++ b/dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy @@ -47,6 +47,8 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory import javax.annotation.Nonnull +import java.util.concurrent.ExecutorCompletionService +import java.util.concurrent.Executors import java.util.function.BiFunction import java.util.function.Function import java.util.function.Supplier @@ -529,9 +531,15 @@ abstract class HttpServerTest extends WithHttpServer { def "test success with #count requests"() { setup: def request = request(SUCCESS, method, body).build() - List responses = (1..count).parallelStream().collect { - return client.newCall(request).execute() + def executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()) + def completionService = new ExecutorCompletionService(executor) + (1..count).each { + completionService.submit { + client.newCall(request).execute() + } } + def responses = (1..count).collect {completionService.take().get()} + if (isDataStreamsEnabled()) { TEST_DATA_STREAMS_WRITER.waitForGroups(1) }