apupier opened a new pull request, #31114: URL: https://github.com/apache/camel/pull/31114
## Description Fixes the flaky `MasterRoutePolicyRouteLifecycleTest` (CAMEL-27547, about 4% of the runs fail on Develocity). ### Root cause `awaitConsuming()` waited with `ServiceHelper.isStarted(consumer)`, which also returns `true` while the consumer is still **starting**. The test then sent a message to `seda:in` while the policy thread was still inside `SedaConsumer.doStart()`. That start registers the consumer on the endpoint, and `SedaEndpoint.registerQueueIfStale()` replaces a stale queue reference. The exchange the producer had already added went to the replaced queue and was never consumed, and the consumer polled the new, empty queue until `assertConsumes` timed out: ``` java.lang.AssertionError: mock://out Received message count. Expected: <1> but was: <0> ``` The TRACE log of a failing run shows the order: `Adding Exchange to queue` (producer, `main`) comes before `Created queue seda://in` and `Elected as master. Consumer started` (group thread). ### Fix `awaitConsuming()` now waits for a fully started consumer (`StatefulService.isStarted()`, not starting). Only the test changes (8 added lines, 1 changed); no assertion is modified and no production code is touched. ### Verification - Reproduced locally by saturating the CPUs (70 busy loops on 22 cores) and running the class in a loop: roughly 1 run in 3 failed, in a different test each time (`failedJoinLeavesNoHalfJoinedState`, `routeAddedAgainWithTheSamePolicyRunsAgain`, `routeAddedAgainWithANewPolicyRunsAgain`, `policyStoppedOnItsOwnLeavesTheGroupAndJoinsAgainWhenStarted`), all at `assertConsumes`. - With the fix, 15 consecutive runs under the same load pass. - The `awaitConsuming` and `awaitSlave` timeouts listed in the ticket (`restartedContextRunsTheRouteAgain`, `removedRouteGivesUpTheMastership`) were **not** reproduced locally, so they are not confirmed as covered. The `awaitConsuming` ones are likely the same cause; `awaitSlave` is unverified. Note for reviewers: the race itself (a message added to a queue that the consumer start then replaces) is in `camel-seda`, which this PR does not change. Whether that deserves a separate production fix is open. JIRA: https://issues.apache.org/jira/browse/CAMEL-27547 --- _Bob (IBM Bob 2.2.1) on behalf of Aurélien Pupier (apupier)_ -- 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]
