CAMEL-24026: Fix flaky XsltFromFileExceptionTest - #25334
Conversation
…file poll PR apache#24625 reordered oneExchangeDone before mock assertions but still flaked when the 10s notify latch timed out on slow CI. Use a 30-second MockEndpoint assertion for route completion and Awaitility to poll until files are moved to ok/error, instead of relying on oneExchangeDone. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Fix summaryAddresses CAMEL-24026 — flaky Why #24625 was revertedPR #24625 reordered to wait on Why this fix is different
Verified./mvnw -pl core/camel-core -am test -Dtest=XsltFromFileExceptionTestAI-generated comment on behalf of atiaomar1978-hub |
Co-authored-by: Omar Atie <atiaomar1978-hub@users.noreply.github.com>
Review follow-up (BugBot + Grok)BugBot: No issues in this test change (unrelated TUI findings are on fork Grok: Fix approach is sound — timed mock wait + Awaitility for post-route file move. Applied feedback: added inline comment explaining why Note: AI-generated comment on behalf of atiaomar1978-hub |
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 24 tested, 0 compile-only — current: 0 all testedMaveniverse Scalpel detected 24 affected modules (current approach: 0).
|
gnodet
left a comment
There was a problem hiding this comment.
Well-reasoned fix for a flaky test with clear prior-attempt analysis.
Root cause: oneExchangeDone is a global NotifyBuilder that fires on the first completed exchange of any kind. Since template.sendBodyAndHeader(fileUri(), ...) itself completes an exchange (the producer write), oneExchangeDone can fire before the file consumer route even picks up the file — making the previous assertion order racy.
Fix: Eliminates the latch entirely and uses the right synchronization:
assertMockEndpointsSatisfied(30, SECONDS)— confirms route processing via MockEndpoint's internalCountDownLatch- Awaitility — polls for the asynchronous file move that occurs after route completion
This two-phase wait correctly models the two asynchronous steps.
Conventions followed correctly:
assertMockEndpointsSatisfied(timeout, unit)used directly, not wrapped in Awaitility- Awaitility reserved for the non-mock filesystem condition
- No
Thread.sleepintroduced publicremoved from test class and methods per JUnit 5 convention- Import ordering correct per
impsort-maven-pluginconfiguration
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of @gnodet
Summary
Fixes CAMEL-24026:
XsltFromFileExceptionTestis flaky on slow CI when the file consumer has not finished before assertions run.Why #24625 was reverted: reordering to wait on
oneExchangeDonefirst still failed — the default 10s notify latch timed out (Exchange should have completedwas false). Simply swapping assertion order was insufficient.This fix (different approach):
assertMockEndpointsSatisfied(30, SECONDS)so mock waits generously for the file consumer route to completeok//error/directories) instead ofoneExchangeDoneoneExchangeDonenotify latch, which races with producer vs consumer exchangesTest plan
./mvnw -pl core/camel-core -am test -Dtest=XsltFromFileExceptionTestAI-generated PR description on behalf of atiaomar1978-hub