Fix ApacheHttpAsync race condition
This commit is contained in:
parent
920b9b5ad3
commit
c5dbd7d0d7
|
@ -1,6 +1,5 @@
|
|||
import datadog.trace.agent.test.base.HttpClientTest
|
||||
import datadog.trace.instrumentation.apachehttpasyncclient.ApacheHttpAsyncClientDecorator
|
||||
import io.opentracing.util.GlobalTracer
|
||||
import org.apache.http.client.methods.HttpGet
|
||||
import org.apache.http.impl.nio.client.HttpAsyncClients
|
||||
import org.apache.http.message.BasicHeader
|
||||
|
@ -34,10 +33,7 @@ class ApacheHttpAsyncClientNullCallbackTest extends HttpClientTest<ApacheHttpAsy
|
|||
Future future = client.execute(request, null)
|
||||
future.get()
|
||||
if (callback != null) {
|
||||
// Request span is closed asynchronously even in regards to returned future so we have to wait here.
|
||||
if (GlobalTracer.get().activeSpan() != null) {
|
||||
blockUntilChildSpansFinished(1)
|
||||
}
|
||||
blockUntilChildSpansFinished(1)
|
||||
callback()
|
||||
}
|
||||
return 200
|
||||
|
|
|
@ -200,6 +200,10 @@ public abstract class AgentTestRunner extends Specification {
|
|||
|
||||
public void blockUntilChildSpansFinished(final int numberOfSpans) throws InterruptedException {
|
||||
final DDSpan span = (DDSpan) io.opentracing.util.GlobalTracer.get().activeSpan();
|
||||
if (span == null) {
|
||||
// If there is no active span avoid getting an NPE
|
||||
return;
|
||||
}
|
||||
final PendingTrace pendingTrace = span.context().getTrace();
|
||||
|
||||
while (pendingTrace.size() < numberOfSpans) {
|
||||
|
|
Loading…
Reference in New Issue