diff --git a/dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy b/dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy index 9bafc945800..b207cbd5f48 100644 --- a/dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy +++ b/dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy @@ -174,6 +174,15 @@ abstract class HttpServerTest extends WithHttpServer { } } + /** + * Hook method to allow subclasses to wait for request processing to complete. + * This is particularly useful for asynchronous HTTP server implementations + * where spans may still not be closed after the HTTP response is sent. + */ + protected void waitForRequestToComplete() { + // Default implementation does nothing - override in subclasses as needed + } + // used in blocking tests to check if the handler was skipped volatile boolean handlerRan @@ -1195,6 +1204,8 @@ abstract class HttpServerTest extends WithHttpServer { TEST_DATA_STREAMS_WRITER.waitForGroups(1) } + waitForRequestToComplete() + expect: response.code() == EXCEPTION.status if (testExceptionBody()) { diff --git a/dd-java-agent/instrumentation/pekko-http-1.0/src/baseTest/groovy/PekkoHttpServerInstrumentationTest.groovy b/dd-java-agent/instrumentation/pekko-http-1.0/src/baseTest/groovy/PekkoHttpServerInstrumentationTest.groovy index 664ee4f0e7f..52fe53cb39d 100644 --- a/dd-java-agent/instrumentation/pekko-http-1.0/src/baseTest/groovy/PekkoHttpServerInstrumentationTest.groovy +++ b/dd-java-agent/instrumentation/pekko-http-1.0/src/baseTest/groovy/PekkoHttpServerInstrumentationTest.groovy @@ -40,6 +40,21 @@ abstract class PekkoHttpServerInstrumentationTest extends HttpServerTest