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.agent.test.base.HttpClientTest
|
||||||
import datadog.trace.instrumentation.apachehttpasyncclient.ApacheHttpAsyncClientDecorator
|
import datadog.trace.instrumentation.apachehttpasyncclient.ApacheHttpAsyncClientDecorator
|
||||||
import io.opentracing.util.GlobalTracer
|
|
||||||
import org.apache.http.client.methods.HttpGet
|
import org.apache.http.client.methods.HttpGet
|
||||||
import org.apache.http.impl.nio.client.HttpAsyncClients
|
import org.apache.http.impl.nio.client.HttpAsyncClients
|
||||||
import org.apache.http.message.BasicHeader
|
import org.apache.http.message.BasicHeader
|
||||||
|
@ -34,10 +33,7 @@ class ApacheHttpAsyncClientNullCallbackTest extends HttpClientTest<ApacheHttpAsy
|
||||||
Future future = client.execute(request, null)
|
Future future = client.execute(request, null)
|
||||||
future.get()
|
future.get()
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
// Request span is closed asynchronously even in regards to returned future so we have to wait here.
|
blockUntilChildSpansFinished(1)
|
||||||
if (GlobalTracer.get().activeSpan() != null) {
|
|
||||||
blockUntilChildSpansFinished(1)
|
|
||||||
}
|
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
return 200
|
return 200
|
||||||
|
|
|
@ -200,6 +200,10 @@ public abstract class AgentTestRunner extends Specification {
|
||||||
|
|
||||||
public void blockUntilChildSpansFinished(final int numberOfSpans) throws InterruptedException {
|
public void blockUntilChildSpansFinished(final int numberOfSpans) throws InterruptedException {
|
||||||
final DDSpan span = (DDSpan) io.opentracing.util.GlobalTracer.get().activeSpan();
|
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();
|
final PendingTrace pendingTrace = span.context().getTrace();
|
||||||
|
|
||||||
while (pendingTrace.size() < numberOfSpans) {
|
while (pendingTrace.size() < numberOfSpans) {
|
||||||
|
|
Loading…
Reference in New Issue