Skip to content

Commit 958c5f6

Browse files
committed
Fix flaky InvokeCallbackWrapperTest due to non-deterministic segment ordering
The test assumed a fixed index order for trace segments, but segment completion order between the main thread and thread pool is non-deterministic. Find the child segment by checking for a non-null ref instead of relying on list index.
1 parent e5d334a commit 958c5f6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

apm-sniffer/apm-sdk-plugin/sofarpc-plugin/src/test/java/org/apache/skywalking/apm/plugin/sofarpc/InvokeCallbackWrapperTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ public void testOnResponse() throws InterruptedException {
141141
TraceSegment traceSegment2 = segmentStorage.getTraceSegments().get(1);
142142
List<AbstractTracingSpan> spans2 = SegmentHelper.getSpans(traceSegment2);
143143
assertThat(spans2.size(), is(1));
144-
assertEquals("sofarpc", traceSegment2.getRef().getParentEndpoint());
144+
145+
// Segment order is non-deterministic; find the child segment (the one with a ref)
146+
TraceSegment childSegment = traceSegment.getRef() != null ? traceSegment : traceSegment2;
147+
assertEquals("sofarpc", childSegment.getRef().getParentEndpoint());
145148
}
146149

147150
@Test
@@ -162,7 +165,11 @@ public void testOnException() throws InterruptedException {
162165
TraceSegment traceSegment2 = segmentStorage.getTraceSegments().get(1);
163166
List<AbstractTracingSpan> spans2 = SegmentHelper.getSpans(traceSegment2);
164167
assertThat(spans2.size(), is(1));
165-
assertThat(SpanHelper.getLogs(spans2.get(0)).size(), is(1));
168+
169+
// Segment order is non-deterministic; find the child segment (the one with a ref)
170+
TraceSegment childSegment = traceSegment.getRef() != null ? traceSegment : traceSegment2;
171+
List<AbstractTracingSpan> childSpans = SegmentHelper.getSpans(childSegment);
172+
assertThat(SpanHelper.getLogs(childSpans.get(0)).size(), is(1));
166173

167174
}
168175

0 commit comments

Comments
 (0)