tmielke opened a new pull request, #30388: URL: https://github.com/apache/camel/pull/30388
## Summary - Fixes the `WSAddressingTest` flakiness reported in [CAMEL-27158](https://issues.apache.org/jira/browse/CAMEL-27158) by adding `@DirtiesContext(classMode = AFTER_CLASS)`. - Root cause: without it, Spring's `ContextCache` reuses a stale `ApplicationContext` — including its already-bound CXF/Undertow listener — across a Surefire rerun, even though the rerun's own `@BeforeAll` mints fresh ports. That mismatch produces the reported `ConnectException`/`ClosedChannelException`. - Declared only on the base class: Spring resolves `@DirtiesContext` per concrete test class, so `WSAddressingPAYLOADTest`/`WSAddressingCXFMSGTest` inherit it without any changes of their own. ## What this fixes, and what it doesn't - This directly fixes the `ConnectException`/`ClosedChannelException` reported on Surefire reruns. - It does **not** fully address the `java.net.BindException: Address already in use` reported on the first attempt — that looks like the same pre-existing, project-wide `AvailablePortFinder` port race already diagnosed and fixed for CAMEL-25788/CAMEL-25583/CAMEL-26365 (camel-cxf-rest/camel-cxf-soap, #28676): `AvailablePort.probePort()` finds a free port via bind-then-close with no cross-process coordination, and our CI (`mvnd -Dmvnd.threads=2`) genuinely builds/tests two Maven modules concurrently on one shared runner, so an unrelated, concurrently-building module can grab the same "free" port moments before this test binds it. That race isn't something this test can fix on its own. - That said, we think this change should still help with the `BindException` symptom in practice: previously, once a Spring context was cached, it stayed cached (and bound to its original ports) for the rest of the fork, so a Surefire rerun (CI already runs with `rerunFailingTestsCount=2`) was never a clean retry — it reused the stale context and failed differently instead. With `@DirtiesContext`, every rerun now starts from a brand-new Spring context and freshly-allocated ports, so a transient bind collision on the first attempt gets a genuinely independent retry rather than one poisoned by leftover state. ## Scope Found ~10 other test classes in `camel-cxf-spring-soap` with the identical at-risk pattern (`AvailablePortFinder` + no `@DirtiesContext`): `Camel1145RouteTest`, `LoggingInterceptorInMessageModeTest`, `ServiceClassRefTest`, `CxfMessageHeadersRelayTest`, `WSRMTest`, and the `CxfMtom*` family. None have been reported flaky, so they're left out of this PR to keep it minimal — may be worth a follow-up ticket to audit them. ## Test plan - [x] `WSAddressingTest`, `WSAddressingPAYLOADTest`, `WSAddressingCXFMSGTest` pass locally. - [x] Verified the caching mechanism directly: drove `WSAddressingTest` through the JUnit Platform launcher twice in one JVM (mirroring a same-fork Surefire rerun) with Spring's context-cache logging at TRACE. Before the fix: one `Storing ApplicationContext` event, with the second run only `Retrieved`-ing the first run's same context. After the fix: two independent `Storing` events, no cross-run reuse. - [x] `mvn formatter:format impsort:sort` — no changes needed. _Claude Code on behalf of tmielke_ -- 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]
