From 26c354dad2a4b6486e708cbbfd80ce3c7fe14eeb Mon Sep 17 00:00:00 2001 From: Gary Huang Date: Fri, 7 Dec 2018 00:44:27 -0500 Subject: [PATCH] Fix Flaky Ratpack Fork Test Ratpack tests occasionally fail with the handler span and manually started span out of order. This will ensure that if a span is manually started inside of the handler then it will be finished after the handler span is finished, which is when the request has been responded to. --- .../ratpack-1.4/src/test/groovy/RatpackTest.groovy | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/dd-java-agent/instrumentation/ratpack-1.4/src/test/groovy/RatpackTest.groovy b/dd-java-agent/instrumentation/ratpack-1.4/src/test/groovy/RatpackTest.groovy index 63c2586f2e..f4e88de0b9 100644 --- a/dd-java-agent/instrumentation/ratpack-1.4/src/test/groovy/RatpackTest.groovy +++ b/dd-java-agent/instrumentation/ratpack-1.4/src/test/groovy/RatpackTest.groovy @@ -320,12 +320,16 @@ class RatpackTest extends AgentTestRunner { ((TraceScope) scope).setAsyncPropagation(true) } scope.span().setBaggageItem("test-baggage", "foo") - context.render(testPromise().fork()) - if (startSpanInHandler) { - ((TraceScope) scope).setAsyncPropagation(false) + context.onClose { + if (startSpanInHandler) { + final Scope activeScope = GlobalTracer.get().scopeManager().active() + ((TraceScope) activeScope).setAsyncPropagation(false) + activeScope.close() + } } - scope.close() + + context.render(testPromise().fork()) } } }