This is an automated email from the ASF dual-hosted git repository.
ffang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/main by this push:
new c57a4b69f4 CXF-9142 Change async tracing tests to be order-agnostic
(#2427)
c57a4b69f4 is described below
commit c57a4b69f44311b2aae75310db01d1ef5732afc7
Author: Tom Cunningham <[email protected]>
AuthorDate: Wed May 28 16:18:54 2025 -0400
CXF-9142 Change async tracing tests to be order-agnostic (#2427)
---
.../opentelemetry/OpenTelemetryTracingTest.java | 29 ++++++++++---
.../opentracing/OpenTracingTracingTest.java | 50 +++++++++++++++++-----
2 files changed, 63 insertions(+), 16 deletions(-)
diff --git
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentelemetry/OpenTelemetryTracingTest.java
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentelemetry/OpenTelemetryTracingTest.java
index e90c2796b3..afc8530389 100644
---
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentelemetry/OpenTelemetryTracingTest.java
+++
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentelemetry/OpenTelemetryTracingTest.java
@@ -255,13 +255,30 @@ public class OpenTelemetryTracingTest extends
AbstractClientServerTestBase {
final Response r =
withTrace(createWebClient("/bookstore/books/async")).get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
- await().atMost(Duration.ofSeconds(1L)).until(() ->
otelRule.getSpans().size() == 2);
+ int spanSize = 2;
+ await().atMost(Duration.ofSeconds(1L)).until(() ->
otelRule.getSpans().size() == spanSize);
- assertThat(otelRule.getSpans().size(), equalTo(2));
- assertEquals("Processing books",
otelRule.getSpans().get(0).getName());
- assertEquals("GET /bookstore/books/async",
otelRule.getSpans().get(1).getName());
-
assertThat(otelRule.getSpans().get(1).getParentSpanContext().isValid(),
equalTo(true));
- assertThat(otelRule.getSpans().get(1).getParentSpanId(),
+ assertThat(otelRule.getSpans().size(), equalTo(spanSize));
+
+ boolean foundProcessing = false;
+ for (int i = 0; i < spanSize; i++) {
+ if ("Processing
books".equals(otelRule.getSpans().get(i).getName())) {
+ foundProcessing = true;
+ }
+ }
+ assertTrue("Could not find Processing books in span
getOperationName()", foundProcessing);
+
+ boolean foundAsync = false;
+ int getIndex = -1;
+ for (int i = 0; i < spanSize; i++) {
+ if ("GET
/bookstore/books/async".equals(otelRule.getSpans().get(i).getName())) {
+ foundAsync = true;
+ getIndex = i;
+ }
+ }
+
+
assertThat(otelRule.getSpans().get(getIndex).getParentSpanContext().isValid(),
equalTo(true));
+ assertThat(otelRule.getSpans().get(getIndex).getParentSpanId(),
equalTo(Span.current().getSpanContext().getSpanId()));
}
}
diff --git
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentracing/OpenTracingTracingTest.java
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentracing/OpenTracingTracingTest.java
index 0bcbe34f5c..53899e9b69 100644
---
a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentracing/OpenTracingTracingTest.java
+++
b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/opentracing/OpenTracingTracingTest.java
@@ -196,13 +196,30 @@ public class OpenTracingTracingTest extends
AbstractClientServerTestBase {
final Response r =
withTrace(createWebClient("/bookstore/books/async"), spanId).get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
- await().atMost(Duration.ofSeconds(1L)).until(()->
REPORTER.getSpans().size() == 2);
+ int spanSize = 2;
+ await().atMost(Duration.ofSeconds(1L)).until(()->
REPORTER.getSpans().size() == spanSize);
+
+ assertThat(REPORTER.getSpans().size(), equalTo(spanSize));
+ boolean foundProcessing = false;
+ for (int i = 0; i < spanSize; i++) {
+ if ("Processing
books".equals(REPORTER.getSpans().get(i).getOperationName())) {
+ foundProcessing = true;
+ }
+ }
+ assertTrue("Could not find Processing books in span
getOperationName()", foundProcessing);
+
+ boolean foundAsync = false;
+ int getIndex = -1;
+ for (int i = 0; i < spanSize; i++) {
+ if ("GET
/bookstore/books/async".equals(REPORTER.getSpans().get(i).getOperationName())) {
+ foundAsync = true;
+ getIndex = 1;
+ }
+ }
+ assertTrue("Could not find GET /bookstore/books/async in span
getOperationName()", foundAsync);
- assertThat(REPORTER.getSpans().size(), equalTo(2));
- assertEquals("Processing books",
REPORTER.getSpans().get(0).getOperationName());
- assertEquals("GET /bookstore/books/async",
REPORTER.getSpans().get(1).getOperationName());
- assertThat(REPORTER.getSpans().get(1).getReferences(), not(empty()));
-
assertThat(REPORTER.getSpans().get(1).getReferences().get(0).getSpanContext().getSpanId(),
+ assertThat(REPORTER.getSpans().get(getIndex).getReferences(),
not(empty()));
+
assertThat(REPORTER.getSpans().get(getIndex).getReferences().get(0).getSpanContext().getSpanId(),
equalTo(spanId.getSpanId()));
}
@@ -222,11 +239,24 @@ public class OpenTracingTracingTest extends
AbstractClientServerTestBase {
final Response r = createWebClient("/bookstore/books/async").get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
- await().atMost(Duration.ofSeconds(1L)).until(()->
REPORTER.getSpans().size() == 2);
+ int spanSize = 2;
+ await().atMost(Duration.ofSeconds(1L)).until(()->
REPORTER.getSpans().size() == spanSize);
- assertThat(REPORTER.getSpans().size(), equalTo(2));
- assertThat(REPORTER.getSpans().get(0).getOperationName(),
equalTo("Processing books"));
- assertThat(REPORTER.getSpans().get(1).getOperationName(), equalTo("GET
/bookstore/books/async"));
+ assertThat(REPORTER.getSpans().size(), equalTo(spanSize));
+ boolean foundProcessing = false;
+ for (int i = 0; i < spanSize; i++) {
+ if ("Processing
books".equals(REPORTER.getSpans().get(i).getOperationName())) {
+ foundProcessing = true;
+ }
+ }
+ assertTrue("Could not find Processing books in span
getOperationName()", foundProcessing);
+
+ boolean foundAsync = false;
+ for (int i = 0; i < spanSize; i++) {
+ if ("GET
/bookstore/books/async".equals(REPORTER.getSpans().get(i).getOperationName())) {
+ foundAsync = true;
+ }
+ }
}
@Test