Fix flaky reactor netty test
MODIFY
instrumentation/reactor-netty/reactor-netty-0.9/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/AbstractReactorNettyHttpClientTest.groovy
instrumentation/reactor-netty/reactor-netty-0.9/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/AbstractReactorNettyHttpClientTest.groovy
@@ -15,6 +15,7 @@ import io.opentelemetry.instrumentation.test.AgentTestTrait
import io.opentelemetry.instrumentation.test.base.HttpClientTest
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest
import io.opentelemetry.sdk.trace.data.SpanData
+import java.util.concurrent.CountDownLatch
import java.util.concurrent.atomic.AtomicReference
import reactor.netty.http.client.HttpClient
@@ -103,12 +104,16 @@ abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest<HttpCli
def afterRequestSpan = new AtomicReference<Span>()
def onResponseSpan = new AtomicReference<Span>()
def afterResponseSpan = new AtomicReference<Span>()
+ def latch = new CountDownLatch(1)
def httpClient = createHttpClient()
.doOnRequest({ rq, con -> onRequestSpan.set(Span.current()) })
.doAfterRequest({ rq, con -> afterRequestSpan.set(Span.current()) })
.doOnResponse({ rs, con -> onResponseSpan.set(Span.current()) })
- .doAfterResponse({ rs, con -> afterResponseSpan.set(Span.current()) })
+ .doAfterResponse({ rs, con ->
+ afterResponseSpan.set(Span.current())
+ latch.countDown()
+ })
when:
runWithSpan("parent") {
@@ -121,6 +126,7 @@ abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest<HttpCli
}
.block()
}
+ latch.await()
then:
assertTraces(1) {
@@ -189,7 +195,6 @@ abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest<HttpCli
}
}
-
private static void assertSameSpan(SpanData expected, AtomicReference<Span> actual) {
def expectedSpanContext = expected.spanContext
def actualSpanContext = actual.get().spanContext

MODIFY
instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/AbstractReactorNettyHttpClientTest.groovy
instrumentation/reactor-netty/reactor-netty-1.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/AbstractReactorNettyHttpClientTest.groovy
@@ -20,6 +20,7 @@ import io.opentelemetry.instrumentation.test.AgentTestTrait
import io.opentelemetry.instrumentation.test.base.HttpClientTest
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest
import io.opentelemetry.sdk.trace.data.SpanData
+import java.util.concurrent.CountDownLatch
import java.util.concurrent.atomic.AtomicReference
import reactor.netty.http.client.HttpClient
@@ -112,12 +113,16 @@ abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest<HttpCli
def afterRequestSpan = new AtomicReference<Span>()
def onResponseSpan = new AtomicReference<Span>()
def afterResponseSpan = new AtomicReference<Span>()
+ def latch = new CountDownLatch(1)
def httpClient = createHttpClient()
.doOnRequest({ rq, con -> onRequestSpan.set(Span.current()) })
.doAfterRequest({ rq, con -> afterRequestSpan.set(Span.current()) })
.doOnResponse({ rs, con -> onResponseSpan.set(Span.current()) })
- .doAfterResponseSuccess({ rs, con -> afterResponseSpan.set(Span.current()) })
+ .doAfterResponseSuccess({ rs, con ->
+ afterResponseSpan.set(Span.current())
+ latch.countDown()
+ })
when:
runWithSpan("parent") {
@@ -130,6 +135,7 @@ abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest<HttpCli
}
.block()
}
+ latch.await()
then:
assertTraces(1) {

Fix flaky reactor netty test (#3966)