Skip to content

Commit 429fb67

Browse files
authored
Merge pull request #845 from DataDog/mar-kolya/fix-test-race-condition
Fix ApacheHttpAsync race condition
2 parents 920b9b5 + c5dbd7d commit 429fb67

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

dd-java-agent/instrumentation/apache-httpasyncclient-4/src/test/groovy/ApacheHttpAsyncClientNullCallbackTest.groovy

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import datadog.trace.agent.test.base.HttpClientTest
22
import datadog.trace.instrumentation.apachehttpasyncclient.ApacheHttpAsyncClientDecorator
3-
import io.opentracing.util.GlobalTracer
43
import org.apache.http.client.methods.HttpGet
54
import org.apache.http.impl.nio.client.HttpAsyncClients
65
import org.apache.http.message.BasicHeader
@@ -34,10 +33,7 @@ class ApacheHttpAsyncClientNullCallbackTest extends HttpClientTest<ApacheHttpAsy
3433
Future future = client.execute(request, null)
3534
future.get()
3635
if (callback != null) {
37-
// Request span is closed asynchronously even in regards to returned future so we have to wait here.
38-
if (GlobalTracer.get().activeSpan() != null) {
39-
blockUntilChildSpansFinished(1)
40-
}
36+
blockUntilChildSpansFinished(1)
4137
callback()
4238
}
4339
return 200

dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/AgentTestRunner.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ public static void assertTraces(
200200

201201
public void blockUntilChildSpansFinished(final int numberOfSpans) throws InterruptedException {
202202
final DDSpan span = (DDSpan) io.opentracing.util.GlobalTracer.get().activeSpan();
203+
if (span == null) {
204+
// If there is no active span avoid getting an NPE
205+
return;
206+
}
203207
final PendingTrace pendingTrace = span.context().getTrace();
204208

205209
while (pendingTrace.size() < numberOfSpans) {

0 commit comments

Comments
 (0)