Skip to content

Commit ba73022

Browse files
committed
feat(kotlin): Add failing tests
1 parent ea4856f commit ba73022

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed

dd-java-agent/instrumentation/kotlin-coroutines/coroutines-1.3/src/test/kotlin/KotlinCoroutineTests.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class KotlinCoroutineTests(dispatcher: CoroutineDispatcher) : CoreKotlinCoroutin
6868
return super.traceAfterTimeout()
6969
}
7070

71+
@Trace
72+
override fun traceAfterDelay(): Int {
73+
return super.traceAfterDelay()
74+
}
75+
7176
@Trace
7277
override fun tracedChild(opName: String) {
7378
super.tracedChild(opName)

dd-java-agent/instrumentation/kotlin-coroutines/coroutines-1.5/src/test/kotlin/KotlinCoroutineTests.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ class KotlinCoroutineTests(dispatcher: CoroutineDispatcher) : CoreKotlinCoroutin
8989
return super.traceAfterTimeout()
9090
}
9191

92+
@Trace
93+
override fun traceAfterDelay(): Int {
94+
return super.traceAfterDelay()
95+
}
96+
9297
@Trace
9398
override fun tracedChild(opName: String) {
9499
super.tracedChild(opName)

dd-java-agent/instrumentation/kotlin-coroutines/src/testFixtures/groovy/datadog/trace/instrumentation/kotlin/coroutines/AbstractKotlinCoroutineInstrumentationTest.groovy

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ abstract class AbstractKotlinCoroutineInstrumentationTest<T extends CoreKotlinCo
376376
assertTraces(1) {
377377
trace(expectedNumberOfSpans, true) {
378378
span(5) {
379-
operationName "top-level"
379+
operationName "trace.annotation"
380380
parent()
381381
}
382382
span(0) {
@@ -406,6 +406,46 @@ abstract class AbstractKotlinCoroutineInstrumentationTest<T extends CoreKotlinCo
406406
[dispatcherName, dispatcher] << dispatchersToTest
407407
}
408408

409+
@Ignore("Not working: disconnected trace")
410+
def "kotlin trace consistent after delay"() {
411+
setup:
412+
CoreKotlinCoroutineTests kotlinTest = getCoreKotlinCoroutineTestsInstance(dispatcher)
413+
int expectedNumberOfSpans = kotlinTest.traceAfterDelay()
414+
415+
expect:
416+
assertTraces(1) {
417+
trace(expectedNumberOfSpans, true) {
418+
span(5) {
419+
operationName "trace.annotation"
420+
parent()
421+
}
422+
span(1) {
423+
operationName "before-process"
424+
childOf span(5)
425+
}
426+
span(2) {
427+
operationName "process-url-a"
428+
childOf span(5)
429+
}
430+
span(3) {
431+
operationName "process-url-b"
432+
childOf span(5)
433+
}
434+
span(4) {
435+
operationName "process-url-c"
436+
childOf span(5)
437+
}
438+
span(0) {
439+
operationName "after-process"
440+
childOf span(5)
441+
}
442+
}
443+
}
444+
445+
where:
446+
[dispatcherName, dispatcher] << dispatchersToTest
447+
}
448+
409449
protected static DDSpan findSpan(List<DDSpan> trace, String opName) {
410450
for (DDSpan span : trace) {
411451
if (span.getOperationName() == opName) {

dd-java-agent/instrumentation/kotlin-coroutines/src/testFixtures/kotlin/datadog/trace/instrumentation/kotlin/coroutines/CoreKotlinCoroutineTests.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,39 @@ abstract class CoreKotlinCoroutineTests(private val dispatcher: CoroutineDispatc
335335
6
336336
}
337337

338+
@Trace
339+
open fun traceAfterDelay(): Int = runTest {
340+
tracedChild("before-process")
341+
342+
val inputs = listOf("a", "b", "c")
343+
344+
coroutineScope {
345+
inputs.map { data ->
346+
async {
347+
upload(data)
348+
}
349+
}.awaitAll().map {
350+
tracedChild("process-$it")
351+
encrypt(it)
352+
}
353+
}
354+
355+
// FIXME: This span is detached
356+
tracedChild("after-process")
357+
358+
6
359+
}
360+
361+
private suspend fun upload(data: String): String {
362+
delay(100)
363+
return "url-$data"
364+
}
365+
366+
private suspend fun encrypt(message: String): String {
367+
delay(100)
368+
return "encrypted-$message"
369+
}
370+
338371
@Trace
339372
protected open fun tracedChild(opName: String) {
340373
activeSpan().setSpanName(opName)

0 commit comments

Comments
 (0)