Skip to content

Commit 344f965

Browse files
committed
Add captureContext specific test
1 parent 2ea0cec commit 344f965

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

dd-java-agent/instrumentation/servicetalk/servicetalk-0.42.0/src/test/groovy/ContextPreservingInstrumentationTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class ContextPreservingInstrumentationTest extends AgentTestRunner {
149149
}
150150
}
151151

152-
private childSpan() {
152+
private static childSpan() {
153153
AgentTracer.startSpan("test", "child").finish()
154154
}
155155
}

dd-java-agent/instrumentation/servicetalk/servicetalk-0.42.56/src/test/groovy/ContextPreservingInstrumentationTest.groovy

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,35 @@ import datadog.trace.bootstrap.instrumentation.api.AgentScope
33
import datadog.trace.bootstrap.instrumentation.api.AgentTracer
44
import io.servicetalk.concurrent.api.AsyncContext
55
import io.servicetalk.concurrent.api.CapturedContext
6-
76
import java.util.concurrent.ExecutorService
87
import java.util.concurrent.Executors
98

109
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
1110

1211
class ContextPreservingInstrumentationTest extends AgentTestRunner {
1312

13+
def "capturedContext"() {
14+
setup:
15+
def parent = startParentContext()
16+
17+
when:
18+
runInSeparateThread {
19+
parent.capturedContext.attachContext()
20+
try (def _ = parent.capturedContext.attachContext()) {
21+
childSpan()
22+
}
23+
}
24+
parent.releaseParentSpan()
25+
26+
then:
27+
assertParentChildTrace()
28+
}
29+
1430
def "wrapBiConsumer"() {
1531
setup:
1632
def parent = startParentContext()
1733
def wrapped =
18-
asyncContextProvider.wrapBiConsumer({ t, u -> childSpan() }, parent.capturedContext)
34+
asyncContextProvider.wrapBiConsumer({ t, u -> childSpan() }, parent.capturedContext)
1935

2036
when:
2137
runInSeparateThread{ wrapped.accept(null, null) }
@@ -29,7 +45,7 @@ class ContextPreservingInstrumentationTest extends AgentTestRunner {
2945
setup:
3046
def parent = startParentContext()
3147
def wrapped =
32-
asyncContextProvider.wrapBiFunction({ t, u -> childSpan() }, parent.capturedContext)
48+
asyncContextProvider.wrapBiFunction({ t, u -> childSpan() }, parent.capturedContext)
3349

3450
when:
3551
runInSeparateThread{ wrapped.apply(null, null) }
@@ -43,7 +59,7 @@ class ContextPreservingInstrumentationTest extends AgentTestRunner {
4359
setup:
4460
def parent = startParentContext()
4561
def wrapped =
46-
asyncContextProvider.wrapCallable({ -> childSpan() }, parent.capturedContext)
62+
asyncContextProvider.wrapCallable({ -> childSpan() }, parent.capturedContext)
4763

4864
when:
4965
runInSeparateThread{ wrapped.call() }
@@ -57,7 +73,7 @@ class ContextPreservingInstrumentationTest extends AgentTestRunner {
5773
setup:
5874
def parent = startParentContext()
5975
def wrapped =
60-
asyncContextProvider.wrapConsumer({ t -> childSpan() }, parent.capturedContext)
76+
asyncContextProvider.wrapConsumer({ t -> childSpan() }, parent.capturedContext)
6177

6278
when:
6379
runInSeparateThread{ wrapped.accept(null) }
@@ -71,7 +87,7 @@ class ContextPreservingInstrumentationTest extends AgentTestRunner {
7187
setup:
7288
def parent = startParentContext()
7389
def wrapped =
74-
asyncContextProvider.wrapFunction({ t -> childSpan() }, parent.capturedContext)
90+
asyncContextProvider.wrapFunction({ t -> childSpan() }, parent.capturedContext)
7591

7692
when:
7793
runInSeparateThread { wrapped.apply(null) }
@@ -85,7 +101,7 @@ class ContextPreservingInstrumentationTest extends AgentTestRunner {
85101
setup:
86102
def parent = startParentContext()
87103
def wrapped =
88-
asyncContextProvider.wrapRunnable({ -> childSpan() }, parent.capturedContext)
104+
asyncContextProvider.wrapRunnable({ -> childSpan() }, parent.capturedContext)
89105

90106
when:
91107
runInSeparateThread(wrapped)
@@ -113,7 +129,6 @@ class ContextPreservingInstrumentationTest extends AgentTestRunner {
113129
*/
114130
private class ParentContext {
115131
final CapturedContext capturedContext = asyncContextProvider.captureContext()
116-
// final CapturedContext capturedContext = asyncContextProvider.captureContextCopy() //TODO
117132
final AgentScope.Continuation spanContinuation = AgentTracer.captureActiveSpan()
118133

119134
def releaseParentSpan() {
@@ -151,7 +166,7 @@ class ContextPreservingInstrumentationTest extends AgentTestRunner {
151166
}
152167
}
153168

154-
private childSpan() {
169+
private static childSpan() {
155170
AgentTracer.startSpan("test", "child").finish()
156171
}
157172
}

0 commit comments

Comments
 (0)