Dhairya-007 opened a new pull request, #31073: URL: https://github.com/apache/camel/pull/31073
# Rationale for this change [CAMEL-20997](https://issues.apache.org/jira/browse/CAMEL-20997) asks for a review of tests that can block indefinitely. Both changes here are waits on the **test thread**, which is the case that actually hangs a CI job — nothing else bounds them. ### `DefaultEndpointRegistryTest#testConcurrency` can hang forever This is the substantive one. The worker counts down **outside any `try`/`finally`**: ```java executorService.submit(() -> { producerTemplate.requestBody("controlbus:route?routeId=route1&...", null, ServiceStatus.class); // ... four more allThreadCompletionSemaphore.countDown(); // never reached if any call throws }); ... allThreadCompletionSemaphore.await(); // unbounded ``` `submit` puts a thrown exception into a `Future` that nobody reads, so it is swallowed. If any of the five `requestBody` calls throws, that worker never counts down, and the test thread sits in `await()` forever. The loop runs 500 iterations across 4 threads, so there are 2000 chances for it. The symptom would be a CI job killed on the overall timeout, with no indication of which test or why — and the underlying exception lost. Three things were wrong, so the fix addresses all three: ```java executorService.submit(() -> { try { ...the five requestBody calls... } catch (Throwable t) { failure.compareAndSet(null, t); // keep it instead of dropping it } finally { allThreadCompletionSemaphore.countDown(); // always runs } }); ... assertTrue(allThreadCompletionSemaphore.await(30, TimeUnit.SECONDS), "the worker threads did not finish iteration " + j); Throwable thrown = failure.get(); if (thrown != null) { throw new AssertionError("a worker threw during iteration " + j, thrown); } ``` Note the `finally` alone would have been the wrong fix on its own: it stops the hang but lets a worker exception pass silently, so the test would go green while doing nothing. Capturing the throwable and rethrowing it as the cause keeps the stack trace and names the iteration. ### `DefaultTracerTraceCounterConcurrencyTest` — bound the completion wait Here the worker already counts down in a `finally`, so this is the lesser case: it only hangs if `template.sendBody` itself never returns. Bounded for the same reason, in the module's AssertJ style: ```java assertThat(doneLatch.await(30, TimeUnit.SECONDS)) .as("the worker threads did not finish sending") .isTrue(); ``` `startGate.await()` in that test's worker is left as it is: it is released by the very next statement, it sits inside the worker's own `try`/`finally`, and bounding it would not change any failure mode. ## What I looked at and deliberately did not change - **`FileLockClusteredRoutePolicyTest#run`** has an unbounded `contextLatch.await()`, but the statement right after it is `RESULTS.add(id)` and the test asserts `RESULTS` contains every client. Simply bounding that wait would record a node as successful after a timeout and turn a real failure into a green run. It needs a different fix, so I left it alone rather than make the test lie. - **Worker-side hold gates** in `DefaultProducerTemplateAsyncStopTest`, `ScheduledPollConsumerHangHealthCheckTest`, `DefaultAsyncProcessorAwaitManagerProcessTest` and `DefaultShutdownStrategyBlockedConsumerTest` park a helper thread on purpose, already catch `InterruptedException`, and are released by `shutdownNow()`. Different discussion, not folded in here. ## Are these changes tested? ```console $ ./mvnw -pl core/camel-core test \ -Dtest='DefaultEndpointRegistryTest,DefaultTracerTraceCounterConcurrencyTest' Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 -- DefaultTracerTraceCounterConcurrencyTest Tests run: 7, Failures: 0, Errors: 0, Skipped: 0 -- DefaultEndpointRegistryTest Tests run: 9, Failures: 0, Errors: 0, Skipped: 0 BUILD SUCCESS ``` `formatter:format` and `impsort:sort` ran as part of that build and left both files unchanged, so the hand-written wrapping and the two new imports are already in the project's style. 30 seconds is the bound in both places: generous for a loaded CI machine, per the 10-30 second guidance in `CLAUDE.md`, and it only costs time when the test is already failing. ## Are there any user-facing changes? No. Test-only. ## Note on the JIRA ticket CAMEL-20997 is Open and unassigned and covers tests across the whole project; this is one slice, so please leave it open. `CLAUDE.md` asks an agent to assign the ticket and move it to In Progress first — I have no ASF JIRA account, so I could not. --- _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]
