Skip to content

Commit a37be87

Browse files
bm1549claude
andcommitted
Fix flaky nested virtual threads test by waiting for child spans
The test was using a CountDownLatch that only ensured child threads had started executing, not that their @trace spans had completed. Replace the latch with blockUntilChildSpansFinished(1) at each nesting level, matching the pattern used by other tests in this class. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cc12228 commit a37be87

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

dd-java-agent/instrumentation/java/java-lang/java-lang-21.0/src/test/java/testdog/trace/instrumentation/java/lang/jdk21/VirtualThreadApiInstrumentationTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import datadog.trace.agent.test.AbstractInstrumentationTest;
88
import datadog.trace.api.Trace;
9-
import java.util.concurrent.CountDownLatch;
109
import java.util.concurrent.ThreadFactory;
1110
import java.util.concurrent.TimeoutException;
1211
import org.junit.jupiter.api.DisplayName;
@@ -96,7 +95,6 @@ public void run() {
9695
@Test
9796
void testNestedVirtualThreads() throws InterruptedException, TimeoutException {
9897
Thread.Builder.OfVirtual threadBuilder = Thread.ofVirtual();
99-
CountDownLatch latch = new CountDownLatch(3);
10098

10199
new Runnable() {
102100
@Trace(operationName = "parent")
@@ -118,20 +116,18 @@ public void run() {
118116
@Override
119117
public void run() {
120118
System.out.println("complete");
121-
latch.countDown();
122119
}
123120
});
124-
latch.countDown();
121+
blockUntilChildSpansFinished(1);
125122
}
126123
});
127-
latch.countDown();
124+
blockUntilChildSpansFinished(1);
128125
}
129126
});
127+
blockUntilChildSpansFinished(1);
130128
}
131129
}.run();
132130

133-
latch.await();
134-
135131
assertTraces(
136132
trace(
137133
SORT_BY_START_TIME,

0 commit comments

Comments
 (0)