Dhairya-007 opened a new pull request, #31077: URL: https://github.com/apache/camel/pull/31077
# Rationale for this change `AsyncTest#testRouteMultipleRequests` waits for asynchronously written spans with a fixed sleep: ```java mock.assertIsSatisfied(1000); // We must wait a safe time to let the context completing the async writing to the log trace. Thread.sleep(10000); Map<String, MockTrace> traces = mockTracer.traces(); ``` The comment says what is wrong with it — "a safe time" is a guess, and it is wrong in both directions. It always costs the full 10 seconds even though the spans normally land in a fraction of that, and on a CI machine loaded enough to need more than 10 seconds the test fails anyway, as a confusing `assertEquals(j, traces.size())` mismatch rather than a timeout. [CAMEL-20997](https://issues.apache.org/jira/browse/CAMEL-20997) asks for exactly this review, and `CLAUDE.md` is explicit: never add `Thread.sleep()`, replace it when touching a test that has one, and use Awaitility with an explicit `atMost` for an asynchronous condition. ## What changed Wait for the condition instead of guessing its duration: ```java await().atMost(30, TimeUnit.SECONDS).until(() -> mockTracer.traces().size() == j); ``` `AsyncWiretapTest`, in this same module, already uses `import static org.awaitility.Awaitility.await;`, so this matches the module's existing style and needs no new dependency. The `atMost` is 30 seconds rather than the 10 the sleep used: it only elapses when the test is already failing, and `CLAUDE.md` asks for generous timeouts on the grounds that a loaded machine is slow. So this is also *more* tolerant of a slow machine than the sleep was, not less. `assertEquals(j, traces.size())` is kept straight after. The Awaitility call is the wait; the assertion is still what reports the failure, and it now reports it against a condition that was genuinely given time to settle. ## Are these changes tested? Same test, same module, before and after, on JDK 21: ```console # before $ ./mvnw -pl components/camel-telemetry test -Dtest=AsyncTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 15.56 s BUILD SUCCESS # after $ ./mvnw -pl components/camel-telemetry test -Dtest=AsyncTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.660 s BUILD SUCCESS ``` It still passes, and the run drops from 15.56s to 5.66s — the ~10 seconds the sleep was spending unconditionally. `formatter:format` and `impsort:sort` ran as part of the build and left the file unchanged. ## Scope `MyAsyncProducer` in the same module also calls `Thread.sleep`, and I left it alone deliberately: it sleeps by a configured endpoint delay to *simulate* a slow producer, which is the fixture's purpose, not a wait for a condition. Converting that would break what the test sets up. This does not resolve CAMEL-20997 — it covers the whole project, and this is one test. ## Are there any user-facing changes? No. Test-only. ## Note on the JIRA ticket CAMEL-20997 is Open and unassigned; `CLAUDE.md` asks an agent to assign it and move it to In Progress first, which I could not do without an ASF JIRA account. Please leave it open. --- _Claude Code on behalf of Dhairya-007_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
