Skip to content

Commit abb87ab

Browse files
authored
Fixing pekko test: revert previous change and fix test server (#9530)
* Revert "add waiting hook in HttpServerTest to try to solve Pekko's flakiness (#9493)" This reverts commit 4644198. * close span on exception handling in pekko test server
1 parent 53dcef9 commit abb87ab

File tree

3 files changed

+5
-27
lines changed

3 files changed

+5
-27
lines changed

dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,6 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
174174
}
175175
}
176176

177-
/**
178-
* Hook method to allow subclasses to wait for request processing to complete.
179-
* This is particularly useful for asynchronous HTTP server implementations
180-
* where spans may still not be closed after the HTTP response is sent.
181-
*/
182-
protected void waitForRequestToComplete() {
183-
// Default implementation does nothing - override in subclasses as needed
184-
}
185-
186177
// used in blocking tests to check if the handler was skipped
187178
volatile boolean handlerRan
188179

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

1207-
waitForRequestToComplete()
1208-
12091198
expect:
12101199
response.code() == EXCEPTION.status
12111200
if (testExceptionBody()) {

dd-java-agent/instrumentation/pekko-http-1.0/src/baseTest/groovy/PekkoHttpServerInstrumentationTest.groovy

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,6 @@ abstract class PekkoHttpServerInstrumentationTest extends HttpServerTest<PekkoHt
4040
true
4141
}
4242

43-
@Override
44-
protected void waitForRequestToComplete() {
45-
// Pekko HTTP is asynchronous, and spans may not be completed
46-
// immediately after the HTTP response is sent. Wait for the trace
47-
// to be written to avoid race conditions in trace assertions.
48-
try {
49-
// Wait up to 1 sec for the trace to be written
50-
TEST_WRITER.waitForTracesMax(1, 1)
51-
} catch (InterruptedException e) {
52-
Thread.currentThread().interrupt()
53-
// If interrupted, proceed anyway - test may still pass
54-
}
55-
}
56-
57-
5843
//@Ignore("https://github.com/DataDog/dd-trace-java/pull/5213")
5944
@Override
6045
boolean testBadUrl() {

dd-java-agent/instrumentation/pekko-http-1.0/src/baseTest/scala/PekkoHttpTestWebServer.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ object PekkoHttpTestWebServer {
136136
private val exceptionHandler = ExceptionHandler {
137137
case e: Exception =>
138138
val span = activeSpan()
139-
TraceUtils.handleException(span, e)
139+
if (span != null) {
140+
// The exception handler is bypassing the normal instrumentation flow, so we need to handle things here
141+
TraceUtils.handleException(span, e)
142+
span.finish()
143+
}
140144
complete(
141145
HttpResponse(status = EXCEPTION.getStatus, entity = e.getMessage)
142146
)

0 commit comments

Comments
 (0)