Skip to content

camel-lumberjack: fix flaky tests by awaiting Netty shutdown#24774

Merged
davsclaus merged 1 commit into
mainfrom
fix/camel-lumberjack-flaky-tests
Jul 16, 2026
Merged

camel-lumberjack: fix flaky tests by awaiting Netty shutdown#24774
davsclaus merged 1 commit into
mainfrom
fix/camel-lumberjack-flaky-tests

Conversation

@davsclaus

Copy link
Copy Markdown
Contributor

Summary

Claude Code on behalf of davsclaus

Fix flaky lumberjack tests caused by incomplete Netty resource cleanup between test runs:

  • Await shutdownGracefully() in LumberjackServer.stop(): the three Netty thread groups (bossGroup, workerGroup, executorService) were shut down fire-and-forget, so the server port could still be in use when the next @Isolated test tried to bind. Now awaits completion with syncUninterruptibly().
  • Await client channel close and event loop in LumberjackUtil: channel.close() was fire-and-forget and shutdownGracefully() on the client event loop was not awaited, which could leave half-open connections that cause spurious ack count mismatches on the server side.
  • Thread-safe ErrorProcessor.count: the int count field in LumberjackDisconnectionTest.ErrorProcessor was read/written from Netty executor threads without synchronization. Replaced with AtomicInteger.
  • Explicit Awaitility timeout: the Awaitility.await() call in LumberjackUtil.sendMessages() relied on the 10-second default, which can be tight on slow CI nodes (especially for SSL tests). Now uses an explicit 30-second timeout.

Test plan

  • mvn test in components/camel-lumberjack — all 5 tests pass
  • CI validates no regressions across platforms

🤖 Generated with Claude Code

- Await shutdownGracefully() on all Netty thread groups in LumberjackServer.stop()
  so the port is fully released before the next test binds a new server
- Await channel.close() and event loop shutdown in test client (LumberjackUtil)
  to prevent half-open connections from causing spurious ack count mismatches
- Make ErrorProcessor.count thread-safe with AtomicInteger in disconnection test
- Add explicit 30s Awaitility timeout in LumberjackUtil (was relying on 10s default)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid flaky-test fix — all four changes are well-motivated.

  1. syncUninterruptibly() on Netty shutdown (LumberjackServer.stop()) — fire-and-forget shutdownGracefully() is the classic cause of port-still-in-use between @Isolated tests. Awaiting completion is the standard Netty pattern.

  2. channel.close().sync() (LumberjackUtil) — ensures the client channel is fully closed before proceeding, preventing half-open connections that cause ack count mismatches.

  3. AtomicInteger for ErrorProcessor.count — the processor runs on Netty executor threads, so the bare int was a legitimate race condition. Clean fix.

  4. Explicit 30s Awaitility timeout — follows the project convention of always setting an explicit atMost rather than relying on the 10s default. 30s is reasonable for SSL tests on slower CI nodes.

Static analysis note: ast-grep flagged a pre-existing ByteArrayOutputStream without try-with-resources in LumberjackUtil.readSample() (line 112) — not introduced by this PR.

Checklist:

  • ✅ Tests: existing tests cover the scenarios; the fix is in resource cleanup, not logic
  • ✅ No public API changes
  • ✅ Backward compatible — shutdown is just properly awaited now
  • ✅ No security concerns
  • ⏳ CI: builds in progress

Reviewed with Claude Code on behalf of gnodet. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • components/camel-lumberjack

🔬 Scalpel shadow comparison — Scalpel: 9 tested, 29 compile-only — current: 9 all tested

Maveniverse Scalpel detected 38 affected modules (current approach: 9).

⚠️ Modules only in Scalpel (29)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • camel-catalog-console
  • camel-catalog-lucene
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-csimple-maven-plugin
  • camel-endpointdsl
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • docs
  • dummy-component

Skip-tests mode would test 9 modules (1 direct + 8 downstream), skip tests for 29 (generated code, meta-modules)

Modules Scalpel would test (9)
  • camel-jbang-mcp
  • camel-jbang-plugin-mcp
  • camel-jbang-plugin-route-parser
  • camel-jbang-plugin-tui
  • camel-jbang-plugin-validate
  • camel-launcher-container
  • camel-lumberjack
  • camel-yaml-dsl-validator
  • camel-yaml-dsl-validator-maven-plugin
Modules with tests skipped (29)
  • apache-camel
  • camel-allcomponents
  • camel-catalog
  • camel-catalog-console
  • camel-catalog-lucene
  • camel-catalog-maven
  • camel-catalog-suggest
  • camel-componentdsl
  • camel-csimple-maven-plugin
  • camel-endpointdsl
  • camel-endpointdsl-support
  • camel-itest
  • camel-jbang-core
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-kamelet-main
  • camel-launcher
  • camel-report-maven-plugin
  • camel-route-parser
  • camel-yaml-dsl
  • camel-yaml-dsl-deserializers
  • camel-yaml-dsl-maven-plugin
  • coverage
  • docs
  • dummy-component

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

All tested modules (38 modules)
  • Camel :: All Components Sync point
  • Camel :: Assembly
  • Camel :: Catalog :: CSimple Maven Plugin (deprecated)
  • Camel :: Catalog :: Camel Catalog
  • Camel :: Catalog :: Camel Report Maven Plugin
  • Camel :: Catalog :: Camel Route Parser
  • Camel :: Catalog :: Console
  • Camel :: Catalog :: Dummy Component
  • Camel :: Catalog :: Lucene (deprecated)
  • Camel :: Catalog :: Maven
  • Camel :: Catalog :: Suggest
  • Camel :: Component DSL
  • Camel :: Coverage
  • Camel :: Docs
  • Camel :: Endpoint DSL
  • Camel :: Endpoint DSL :: Support
  • Camel :: Integration Tests
  • Camel :: JBang :: Core
  • Camel :: JBang :: Integration tests
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Main
  • Camel :: JBang :: Plugin :: Edit
  • Camel :: JBang :: Plugin :: Generate
  • Camel :: JBang :: Plugin :: Kubernetes
  • Camel :: JBang :: Plugin :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Testing
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: Kamelet Main
  • Camel :: Launcher
  • Camel :: Launcher :: Container
  • Camel :: Lumberjack
  • Camel :: YAML DSL
  • Camel :: YAML DSL :: Deserializers
  • Camel :: YAML DSL :: Maven Plugins
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin

⚙️ View full build and test results

windows.stream().forEach(window -> channel.writeAndFlush(readSample(String.format("io/window%s.bin", window))));
if (waitForResult) {
Awaitility.await().until(() -> windows.size() == responses.size());
Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> windows.size() == responses.size());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davsclaus davsclaus added this to the 4.22.0 milestone Jul 16, 2026
@davsclaus davsclaus self-assigned this Jul 16, 2026
@davsclaus davsclaus added the bug Something isn't working label Jul 16, 2026
@davsclaus
davsclaus merged commit 8d82d17 into main Jul 16, 2026
5 checks passed
@davsclaus
davsclaus deleted the fix/camel-lumberjack-flaky-tests branch July 16, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants