Skip to content

Commit 106ceb0

Browse files
bm1549claude
andcommitted
Fix flaky KafkaClientDataStreamsDisabledForkedTest batch consume test
The test mapped consumer traces to producer spans by positional index after SORT_TRACES_BY_ID sorting. Since trace IDs are random, the consumer-to-producer mapping was non-deterministic, causing intermittent `span.parentId == parent.spanId` assertion failures. Fix by dynamically finding each consumer span's actual parent producer span via parentId matching instead of relying on sort order. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cc12228 commit 106ceb0

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

dd-java-agent/instrumentation/kafka/kafka-clients-0.11/src/test/groovy/KafkaClientTestBase.groovy

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -923,14 +923,17 @@ abstract class KafkaClientTestBase extends VersionedNamingTestBase {
923923
queueSpan(it, trace(0)[2])
924924
}
925925
} else {
926-
trace(1) {
927-
consumerSpan(it, consumerProperties, trace(0)[6], 0..0)
928-
}
929-
trace(1) {
930-
consumerSpan(it, consumerProperties, trace(0)[4], 0..1)
931-
}
932-
trace(1) {
933-
consumerSpan(it, consumerProperties, trace(0)[2], 0..1)
926+
// Consumer traces are sorted by random span ID, so we can't assume a fixed
927+
// mapping between consumer trace index and producer span index. Instead, find
928+
// the actual parent producer span for each consumer trace dynamically.
929+
def producerSpans = [trace(0)[2], trace(0)[4], trace(0)[6]]
930+
(1..3).each { traceIdx ->
931+
def consumerSpanParentId = trace(traceIdx)[0].parentId
932+
def parentProducerSpan = producerSpans.find { it.spanId == consumerSpanParentId }
933+
assert parentProducerSpan != null : "Consumer trace $traceIdx has no matching producer span"
934+
trace(1) {
935+
consumerSpan(it, consumerProperties, parentProducerSpan, 0..1)
936+
}
934937
}
935938
}
936939
}

0 commit comments

Comments
 (0)