ammachado opened a new pull request, #31382: URL: https://github.com/apache/camel/pull/31382
# Description [CAMEL-28073](https://issues.apache.org/jira/browse/CAMEL-28073): camel-netty unit tests take about 300 s on CI and sit on the critical path. The [build scan](https://develocity.apache.org/s/loxdlowkzkqng/timeline) shows all classes running one after another, with the CI runner at about 98% CPU. So the gain has to come from lighter tests, not more parallelism. Locally the tests spent most of their time **waiting**, not working: | | Before | After | |---|---|---| | `mvn test` wall clock (camel-netty) | 77 s | 31 s | | Sum of test method times | 74 s | 24.5 s | | Median test method | 0.216 s | 0.009 s | | CPU (user + system) | 86 s | 46 s | Only test code changes; no production code. **Shared event loops (`BaseNettyTest`).** A TCP server stops its own boss and worker groups with Netty's 2 s quiet period, then waits up to `shutdownTimeout` (100 ms) for each one. The quiet period never ends in time, so every server stop waited 200 ms. Every producer and server also created its own event loops. `BaseNettyTest` now gives the netty component event loops shared by all tests in the JVM, whose `shutdownGracefully` does nothing (`NettyComponent.doStop` shuts down a configured worker group). This is the same approach as camel-netty-http in CAMEL-28074. Tests that need the endpoint's own event loops opt out with `isUseSharedEventLoopGroups()`: - `NettyConsumerClientModeStopTest` tests stopping its own worker group. - `NettyTCPChainedTest` uses `workerCount=1`. - `NettyTCPSyncUDSTest` uses `nativeTransport`. - `NettyManualEndpointTest` adds its own component. - `NettySuspendResumeTest`: the suspend must close the open connection. **Other fixed waits** - Event loop groups owned by a test are shut down with no quiet period, after the CamelContext has stopped. The UDP and shared-pool tests used to wait out the 2 s quiet period. - Seda consumers use `pollTimeout=100`. A seda consumer sleeps up to `pollTimeout` (1 s) while the context starts, and the stop waits for its poll. - `NettyRequestTimeoutTest` waits for the server to finish a timed out request. Otherwise the shutdown strategy waits for it in steps of 1 s. - `NettyProducerSyncFalseReplyTest` waits until the server route has completed, then checks over 200 ms, instead of a fixed 1 s. - `NettyConsumerClientModeStopTest`: the "no connection after the stop" windows are 500 ms, which is 5 reconnect intervals. The wait for a reconnect already in progress stays at 1 s. - `NettyProducerAsyncEndpointTest`: server delay of 100 ms instead of 1 s. - `NettyUdpWithInOutUsingPlainSocketTest`: the sleep before a blocking `receive` is replaced by a receive timeout, so a lost reply fails the test instead of hanging it. **Verification (local, macOS)** - Full module: 207 tests, 0 failures, 9 skipped (the same skips as before). - 3 runs with `-Dcamel.surefire.forkCount=8`: all green after `NettySuspendResumeTest` was opted out. - `-Pleaks` (PARANOID leak detection): green, no leak reports. **Seen during the work but not fixed here:** - Once in about 25 runs (before the shared event loops), `NettyUdpWithInOutUsingPlainSocketTest` got an oversized UDP frame from an unknown sender in the same JVM. It hasn't recurred since, and the cause is not found. - One `NettyProducerIdleChannelResetTest` error in an 8-fork run; 8 repeated runs passed. - `NettyUseSharedWorkerThreadPoolManyRoutesTest` reserves 60 ports and can hit the `AvailablePortFinder` race with client ephemeral ports. `SpringNettyUseSharedWorkerThreadPoolTest` uses fixed ports 5021 to 5023 and still waits about 1 s in its Spring `destroy-method="shutdownGracefully"`. - A production follow-up to consider: the consumer stop always waits `shutdownTimeout` twice, because the futures of `shutdownGracefully()` cannot complete within it. That wait was added on purpose in CAMEL-21952. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. Not from the root folder: I built `components/camel-netty` (test-only change, no generated files) and ran `mvn formatter:format impsort:sort` there; `git status` is clean. # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. 🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of Adriano Machado (@ammachado) _This was generated by an AI agent and may contain inaccuracies. Please verify before relying on it._ -- 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]
