Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
}
}

/**
* 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

Expand Down Expand Up @@ -1195,6 +1204,8 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
TEST_DATA_STREAMS_WRITER.waitForGroups(1)
}

waitForRequestToComplete()

expect:
response.code() == EXCEPTION.status
if (testExceptionBody()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ abstract class PekkoHttpServerInstrumentationTest extends HttpServerTest<PekkoHt
true
}

@Override
protected void waitForRequestToComplete() {
// Pekko HTTP is asynchronous, and spans may not be completed
// immediately after the HTTP response is sent. Wait for the trace
// to be written to avoid race conditions in trace assertions.
try {
// Wait up to 1 sec for the trace to be written
TEST_WRITER.waitForTracesMax(1, 1)
} catch (InterruptedException e) {
Thread.currentThread().interrupt()
// If interrupted, proceed anyway - test may still pass
}
}


//@Ignore("https://github.com/DataDog/dd-trace-java/pull/5213")
@Override
boolean testBadUrl() {
Expand Down