Skip to content

Commit f100979

Browse files
bm1549claude
andcommitted
Fix remaining test methods for RANDOM ID strategy
Update 6 more test methods that use SORT_TRACES_BY_ID with hardcoded positional trace references to use SORT_TRACES_BY_START, so they work with the KafkaClientDsmDisabledRandomIdsForkedTest that uses RANDOM span IDs. For the backwards iteration test with 9 traces, also use dynamic parent matching since consumer trace ordering may vary. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 24d96fd commit f100979

1 file changed

Lines changed: 32 additions & 22 deletions

File tree

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

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ abstract class KafkaClientTestBase extends VersionedNamingTestBase {
422422
received.value() == greeting
423423
received.key() == null
424424

425-
assertTraces(2, SORT_TRACES_BY_ID) {
425+
// Use SORT_TRACES_BY_START so the producer trace (started first) is always trace(0)
426+
// regardless of span ID generation strategy.
427+
assertTraces(2, SORT_TRACES_BY_START) {
426428
trace(3) {
427429
basicSpan(it, "parent")
428430
basicSpan(it, "producer callback", span(0))
@@ -542,7 +544,9 @@ abstract class KafkaClientTestBase extends VersionedNamingTestBase {
542544
received.value() == null
543545
received.key() == null
544546

545-
assertTraces(2, SORT_TRACES_BY_ID) {
547+
// Use SORT_TRACES_BY_START so the producer trace (started first) is always trace(0)
548+
// regardless of span ID generation strategy.
549+
assertTraces(2, SORT_TRACES_BY_START) {
546550
trace(1) {
547551
producerSpan(it, senderProps, null, false, true)
548552
}
@@ -596,7 +600,7 @@ abstract class KafkaClientTestBase extends VersionedNamingTestBase {
596600
first.value() == greeting
597601
first.key() == null
598602
599-
assertTraces(2, SORT_TRACES_BY_ID) {
603+
assertTraces(2, SORT_TRACES_BY_START) {
600604
trace(1) {
601605
producerSpan(it, senderProps)
602606
}
@@ -651,7 +655,7 @@ abstract class KafkaClientTestBase extends VersionedNamingTestBase {
651655
first.value() == greeting
652656
first.key() == null
653657
654-
assertTraces(2, SORT_TRACES_BY_ID) {
658+
assertTraces(2, SORT_TRACES_BY_START) {
655659
trace(1) {
656660
producerSpan(it, senderProps)
657661
}
@@ -706,7 +710,7 @@ abstract class KafkaClientTestBase extends VersionedNamingTestBase {
706710
last.value() == greeting
707711
last.key() == null
708712
709-
assertTraces(2, SORT_TRACES_BY_ID) {
713+
assertTraces(2, SORT_TRACES_BY_START) {
710714
trace(1) {
711715
producerSpan(it, senderProps)
712716
}
@@ -764,7 +768,9 @@ abstract class KafkaClientTestBase extends VersionedNamingTestBase {
764768
}
765769
receivedSet.isEmpty()
766770
767-
assertTraces(9, SORT_TRACES_BY_ID) {
771+
// Use SORT_TRACES_BY_START so producer traces (started first) come before consumer traces
772+
// regardless of span ID generation strategy.
773+
assertTraces(9, SORT_TRACES_BY_START) {
768774
769775
// producing traces
770776
trace(1) {
@@ -792,14 +798,17 @@ abstract class KafkaClientTestBase extends VersionedNamingTestBase {
792798
queueSpan(it, trace(2)[0])
793799
}
794800
} else {
795-
trace(1) {
796-
consumerSpan(it, consumerProperties, trace(0)[0], 0..0)
797-
}
798-
trace(1) {
799-
consumerSpan(it, consumerProperties, trace(1)[0], 1..1)
800-
}
801-
trace(1) {
802-
consumerSpan(it, consumerProperties, trace(2)[0], 2..2)
801+
// With SORT_TRACES_BY_START, producer traces are at indices 0-2 and consumer
802+
// traces follow. Use dynamic parent matching since start-time ordering within
803+
// the consumer group may vary with different ID generation strategies.
804+
def producerSpans = [trace(0)[0], trace(1)[0], trace(2)[0]]
805+
(3..5).each { traceIdx ->
806+
def consumerSpanParentId = trace(traceIdx)[0].parentId
807+
def parentProducerSpan = producerSpans.find { it.spanId == consumerSpanParentId }
808+
assert parentProducerSpan != null : "Forward consumer trace $traceIdx has no matching producer span"
809+
trace(1) {
810+
consumerSpan(it, consumerProperties, parentProducerSpan)
811+
}
803812
}
804813
}
805814
@@ -818,14 +827,15 @@ abstract class KafkaClientTestBase extends VersionedNamingTestBase {
818827
queueSpan(it, trace(0)[0])
819828
}
820829
} else {
821-
trace(1) {
822-
consumerSpan(it, consumerProperties, trace(2)[0], 2..2)
823-
}
824-
trace(1) {
825-
consumerSpan(it, consumerProperties, trace(1)[0], 1..1)
826-
}
827-
trace(1) {
828-
consumerSpan(it, consumerProperties, trace(0)[0], 0..0)
830+
// Same dynamic parent matching for backward iteration consumer traces
831+
def producerSpans2 = [trace(0)[0], trace(1)[0], trace(2)[0]]
832+
(6..8).each { traceIdx ->
833+
def consumerSpanParentId = trace(traceIdx)[0].parentId
834+
def parentProducerSpan = producerSpans2.find { it.spanId == consumerSpanParentId }
835+
assert parentProducerSpan != null : "Backward consumer trace $traceIdx has no matching producer span"
836+
trace(1) {
837+
consumerSpan(it, consumerProperties, parentProducerSpan)
838+
}
829839
}
830840
}
831841
}

0 commit comments

Comments
 (0)