Skip to content

Commit 530a3d1

Browse files
add test to verify trace does not propagate when TPE is instantiated (#7711)
1 parent 4eeed47 commit 530a3d1

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package executor
2+
3+
import datadog.trace.agent.test.AgentTestRunner
4+
import datadog.trace.bootstrap.instrumentation.api.AgentTracer
5+
6+
import java.util.concurrent.Executors
7+
import java.util.concurrent.ThreadPoolExecutor
8+
import java.util.concurrent.atomic.AtomicBoolean
9+
10+
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
11+
12+
class ContextLeakTest extends AgentTestRunner {
13+
14+
def "trace should not leak into TPE Worker task when '#name'"() {
15+
setup:
16+
AtomicBoolean parentSpanActive = new AtomicBoolean(false)
17+
def tpe = Executors.newFixedThreadPool(1) as ThreadPoolExecutor
18+
19+
when: "tpe prestarted under an active trace"
20+
runUnderTrace("span") {
21+
interaction(tpe)
22+
}
23+
// submit a probe to check if the span is active or not
24+
tpe.submit {
25+
parentSpanActive.set(AgentTracer.activeSpan()?.operationName == "span")
26+
}.get()
27+
28+
then: "the prestart time span did not leak into the worker"
29+
!parentSpanActive.get()
30+
31+
where:
32+
name | interaction
33+
"prestart all core threads" | { e -> assert e.prestartAllCoreThreads() > 0 : "threads already started" }
34+
"prestart core thread" | { e -> assert e.prestartCoreThread() : "thread already started" }
35+
"lazy init worker" | { e -> e.execute {} }
36+
}
37+
}

0 commit comments

Comments
 (0)