This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 91e54cc48130 CAMEL-20997: camel-telemetry - wait for the traces
instead of sleeping 10 seconds (#31077)
91e54cc48130 is described below
commit 91e54cc4813085a3b3bea0d5a9bdf0b23dbac112
Author: dhairya05 <[email protected]>
AuthorDate: Fri Dec 4 00:54:23 2026 +0530
CAMEL-20997: camel-telemetry - wait for the traces instead of sleeping 10
seconds (#31077)
AsyncTest#testRouteMultipleRequests waits for asynchronously written spans
with Thread.sleep(10000). Its own comment gives it away -- "a safe time" is
a
guess, and it is wrong both ways: it always costs the full 10 seconds
although
the spans normally land in a fraction of that, and on a machine loaded
enough
to need longer the test fails as a confusing traces.size() mismatch rather
than a timeout.
Wait for the condition instead:
await().atMost(30, TimeUnit.SECONDS).until(() ->
mockTracer.traces().size() == j);
AsyncWiretapTest in this same module already imports Awaitility.await, so
this
matches the module style and adds no dependency. The 30 second atMost only
elapses when the test is already failing, so this is more tolerant of a slow
machine than the 10 second sleep was, per the timeout guidance in CLAUDE.md.
The test still passes and drops from 15.56s to 5.66s.
MyAsyncProducer in the same module keeps its Thread.sleep: it sleeps by a
configured endpoint delay to simulate a slow producer, which is the
fixture's
purpose, not a wait for a condition.
Co-Authored-By: Claude <[email protected]>
---
.../src/test/java/org/apache/camel/telemetry/AsyncTest.java | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git
a/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/AsyncTest.java
b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/AsyncTest.java
index 9d3d0b298c71..d73b933c9f9e 100644
---
a/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/AsyncTest.java
+++
b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/AsyncTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.telemetry;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
@@ -30,6 +31,7 @@ import org.apache.camel.telemetry.mock.MockTracer;
import org.apache.camel.test.junit6.ExchangeTestSupport;
import org.junit.jupiter.api.Test;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -61,8 +63,9 @@ public class AsyncTest extends ExchangeTestSupport {
context.createProducerTemplate().sendBody("direct:start",
"Hello!");
}
mock.assertIsSatisfied(1000);
- // We must wait a safe time to let the context completing the async
writing to the log trace.
- Thread.sleep(10000);
+ // The spans are written asynchronously, so wait for every trace to
land instead of
+ // guessing how long that takes.
+ await().atMost(30, TimeUnit.SECONDS).until(() ->
mockTracer.traces().size() == j);
Map<String, MockTrace> traces = mockTracer.traces();
// Each trace should have a unique trace id. It is enough to assert
that
// the number of elements in the map is the same of the requests to
prove