Wait for span to finish instead of ignoring test
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
-import org.junit.Ignore
import spock.lang.AutoCleanup
import spock.lang.Shared
import java.util.concurrent.Future
-/**
- * TODO: we would like not to ugnore this test, but currently this test is flaky
- * The problem is that http-request span is closed asynchronously and when we provide no callback (like 39)
- * we cannot synchronise on when it is closed. Possible soltion here would be to rewrite this to not run
- * tests will callbacks somehow because they make no sense in 'fire-and-forget' scenarios.
- */
-@Ignore
class ApacheHttpAsyncClientNullCallbackTest extends HttpClientTest<ApacheHttpAsyncClientDecorator> {
@AutoCleanup
@@ -41,6 +34,10 @@ 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)
+ }
callback()
}
return 200
