Skip to content

Commit f5167a7

Browse files
Fixed failed tests
1 parent 925dc31 commit f5167a7

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

dd-java-agent/instrumentation/kafka/kafka-clients-0.11/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ dependencies {
4444
testRuntimeOnly project(':dd-java-agent:instrumentation:jackson-core:jackson-core-2.8')
4545
testImplementation(group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.11.4')
4646

47-
// This module still needs JUnit4.
48-
testImplementation(libs.junit4) // TODO spock.junit4?
47+
// This module still needs Spock with JUnit4.
48+
testImplementation(libs.spock.junit4.groovy4)
4949

5050
// Include latest version of kafka itself along with latest version of client libs.
5151
latestDepTestImplementation group: 'org.apache.kafka', name: 'kafka-clients', version: '2.+'

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

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,47 @@ import datadog.trace.api.Trace
22
import datadog.trace.instrumentation.kotlin.coroutines.CoreKotlinCoroutineTests
33
import kotlinx.coroutines.CoroutineDispatcher
44
import kotlinx.coroutines.Dispatchers
5+
import kotlinx.coroutines.flow.Flow
6+
import kotlinx.coroutines.flow.FlowCollector
7+
import kotlinx.coroutines.flow.channelFlow
58
import kotlinx.coroutines.flow.flow
69
import kotlinx.coroutines.flow.flowOn
710
import kotlinx.coroutines.flow.single
811
import kotlinx.coroutines.launch
912
import kotlinx.coroutines.withTimeout
1013

14+
// Workaround for Groovy 4 breaking Kotlin SAM conversion for FlowCollector
15+
private suspend inline fun <T> Flow<T>.forEach(crossinline action: suspend (T) -> Unit) = collect(object : FlowCollector<T> {
16+
override suspend fun emit(value: T) = action(value)
17+
})
18+
1119
class KotlinCoroutineTests(dispatcher: CoroutineDispatcher) : CoreKotlinCoroutineTests(dispatcher) {
1220

13-
// @Trace
14-
// fun tracedAcrossFlows(withModifiedContext: Boolean): Int = runTest {
15-
// val producer = flow {
16-
// repeat(3) {
17-
// tracedChild("produce_$it")
18-
// if (withModifiedContext) {
19-
// withTimeout(100) {
20-
// emit(it)
21-
// }
22-
// } else {
23-
// emit(it)
24-
// }
25-
// }
26-
// }.flowOn(jobName("producer"))
27-
//
28-
// launch(jobName("consumer")) {
29-
// producer.collect {
30-
// tracedChild("consume_$it")
31-
// }
32-
// }
33-
//
34-
// 7
35-
// }
21+
@Trace
22+
fun tracedAcrossFlows(withModifiedContext: Boolean): Int = runTest {
23+
// Use channelFlow when emitting from modified context (withTimeout) as regular flow doesn't allow it
24+
val producer: Flow<Int> = if (withModifiedContext) {
25+
channelFlow {
26+
repeat(3) {
27+
tracedChild("produce_$it")
28+
withTimeout(100) { send(it) }
29+
}
30+
}
31+
} else {
32+
flow {
33+
repeat(3) {
34+
tracedChild("produce_$it")
35+
emit(it)
36+
}
37+
}
38+
}.flowOn(jobName("producer"))
39+
40+
launch(jobName("consumer")) {
41+
producer.forEach { tracedChild("consume_$it") }
42+
}
43+
44+
7
45+
}
3646

3747
@Trace
3848
fun traceAfterFlow(): Int = runTest {

0 commit comments

Comments
 (0)