Skip to content

Commit 86ed7ca

Browse files
bm1549claude
andcommitted
Fix JMS1 CLIENT_ACKNOWLEDGE flaky test by tolerating early scope cleanup
The "receiving messages from TEMPORARY_TOPIC with manual acknowledgement" test in JMS1V1ForkedTest was flaky because the scope iteration keep-alive cleanup (set to 1 second in tests) could finish the 3rd consumer span before acknowledge() was called, producing 6 traces instead of expected 5. Root cause: In the legacy context manager path, activateNext() schedules a root iteration scope cleanup. If this fires before the test's intermediate assertTraces(5) check, the 3rd consumer trace is already complete. Fix: Use assertTraces(5, true) for the intermediate assertion to tolerate additional traces. Also fix ListWriterAssert.ignoreAdditionalTraces to properly use >= instead of == for the size check, matching the behavior of the Java TraceAssertions class. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3f32873 commit 86ed7ca

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

dd-java-agent/instrumentation/jms/javax-jms-1.1/src/test/groovy/JMS1Test.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import datadog.trace.api.config.TraceInstrumentationConfig
1111
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags
1212
import datadog.trace.bootstrap.instrumentation.api.Tags
1313
import datadog.trace.core.DDSpan
14-
import datadog.trace.test.util.Flaky
1514
import org.apache.activemq.ActiveMQConnectionFactory
1615
import org.apache.activemq.command.ActiveMQTextMessage
1716
import org.apache.activemq.junit.EmbeddedActiveMQBroker
@@ -256,7 +255,6 @@ abstract class JMS1Test extends VersionedNamingTestBase {
256255
DestinationType.TEMPORARY_TOPIC | _
257256
}
258257

259-
@Flaky(value = "Race condition: TEMPORARY_TOPIC consumer trace for message3 may complete before acknowledge() is called", suites = ["JMS1V1ForkedTest"])
260258
def "receiving messages from #destinationType with manual acknowledgement"() {
261259
setup:
262260
def destination = destinationType.create(session)
@@ -278,8 +276,10 @@ abstract class JMS1Test extends VersionedNamingTestBase {
278276
receivedMessage1.text == messageText1
279277
receivedMessage2.text == messageText2
280278
receivedMessage3.text == messageText3
281-
// only two consume traces will be finished at this point
282-
assertTraces(5) {
279+
// At least two consume traces will be finished at this point (3 producer + 2 consumer = 5).
280+
// The 3rd consumer trace may also be finished early due to the scope iteration keep-alive
281+
// cleanup firing before acknowledge() is called, so we tolerate 5 or 6 traces here.
282+
assertTraces(5, true) {
283283
producerTraceWithNaming(it, destination)
284284
producerTraceWithNaming(it, destination)
285285
producerTraceWithNaming(it, destination)

dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/asserts/ListWriterAssert.groovy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ class ListWriterAssert {
4949
try {
5050
writer.waitForTraces(expectedSize)
5151
def array = writer.toArray()
52-
assert array.length == expectedSize
52+
if (ignoreAdditionalTraces) {
53+
assert array.length >= expectedSize
54+
} else {
55+
assert array.length == expectedSize
56+
}
5357
def traces = (Arrays.asList(array) as List<List<DDSpan>>)
5458
Collections.sort(traces, traceSorter)
5559
def asserter = new ListWriterAssert(traces)

0 commit comments

Comments
 (0)