Skip to content

CAMEL-19528: Replace CountDownLatch with Awaitility in camel-jpa tests#24411

Merged
gnodet merged 1 commit into
apache:mainfrom
gnodet:fix/CAMEL-19528
Jul 4, 2026
Merged

CAMEL-19528: Replace CountDownLatch with Awaitility in camel-jpa tests#24411
gnodet merged 1 commit into
apache:mainfrom
gnodet:fix/CAMEL-19528

Conversation

@gnodet

@gnodet gnodet commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replace flaky CountDownLatch-based synchronization with Awaitility await().untilAsserted() in JPA consumer tests (JpaWithNamedQueryTest, JpaTest, JpaWithNamedQueryAndParametersTest)
  • Re-enable 3 tests previously disabled on CI (JpaWithQueryTest, JpaWithNativeQueryTest, JpaWithNativeQueryWithResultClassTest) by removing @DisabledIfSystemProperty annotations — the underlying timing issue in their parent class is now fixed
  • Mark receivedExchange fields as volatile for correct cross-thread visibility

Root cause: The CountDownLatch + latch.await(timeout) pattern in consumer tests was timing-sensitive. The JPA consumer uses scheduled polling (1s initial delay, 500ms interval), and under CI load the consumer poll could arrive after the fixed deadline, causing hangs or assertion failures. Awaitility's polling approach retries the assertion until it passes, making the tests resilient to scheduling jitter.

Test plan

  • All 96 camel-jpa tests pass locally (including the 3 re-enabled tests)
  • No Thread.sleep or CountDownLatch remaining in modified test files
  • Code formatted with mvn formatter:format impsort:sort

Claude Code on behalf of Guillaume Nodet

🤖 Generated with Claude Code

Replace flaky CountDownLatch-based synchronization with Awaitility
polling in JPA consumer tests. The CountDownLatch pattern caused
intermittent hangs and timeouts in CI because the JPA consumer's
scheduled polling (1s initial delay, 500ms interval) could miss the
fixed deadline under load.

Changes:
- JpaWithNamedQueryTest: replace CountDownLatch + latch.await() with
  Awaitility await().untilAsserted()
- JpaTest: same CountDownLatch to Awaitility migration
- JpaWithNamedQueryAndParametersTest: same migration
- Re-enable JpaWithQueryTest, JpaWithNativeQueryTest, and
  JpaWithNativeQueryWithResultClassTest by removing
  @DisabledIfSystemProperty annotations (the underlying timing
  issue in their parent class is now fixed)
- Mark receivedExchange fields as volatile for thread-safe publication

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet requested review from davsclaus and orpiske July 3, 2026 17:48
@github-actions

github-actions Bot commented Jul 3, 2026

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.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • components/camel-jpa

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

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

Modules only in current approach (8)
  • camel-jbang-mcp
  • camel-jbang-plugin-mcp
  • camel-jbang-plugin-route-parser
  • camel-jbang-plugin-tui
  • camel-jbang-plugin-validate
  • camel-launcher-container
  • camel-yaml-dsl-validator
  • camel-yaml-dsl-validator-maven-plugin

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

Modules Scalpel would test (1)
  • camel-jpa

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

All tested modules (9 modules)
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Plugin :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: JPA
  • Camel :: Launcher :: Container
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin

⚙️ View full build and test results

@gnodet gnodet marked this pull request as ready for review July 3, 2026 21:02
@gnodet gnodet requested a review from Copilot July 3, 2026 21:02

Copilot AI 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.

Pull request overview

This PR improves the reliability of camel-jpa consumer tests by replacing timing-sensitive CountDownLatch synchronization with Awaitility-based polling and by re-enabling previously CI-disabled test classes now that the underlying flakiness is addressed.

Changes:

  • Replaced CountDownLatch-based waiting with await().untilAsserted(...) in JPA consumer tests and made receivedExchange volatile for cross-thread visibility.
  • Re-enabled CI-disabled test classes by removing @DisabledIfSystemProperty guards and standardizing on @Timeout(30).
  • Kept assertions resilient to scheduling jitter by retrying until conditions are met (within explicit time bounds).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithQueryTest.java Re-enables the test on CI by removing CI-specific disabling.
components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNativeQueryWithResultClassTest.java Re-enables the test on CI and adds a class-level timeout.
components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNativeQueryTest.java Re-enables the test on CI by removing CI-specific disabling.
components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java Replaces latch synchronization with Awaitility and makes receivedExchange volatile.
components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryAndParametersTest.java Replaces latch synchronization with Awaitility and makes receivedExchange volatile.
components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaTest.java Replaces latch synchronization with Awaitility and makes receivedExchange volatile.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gnodet gnodet merged commit feab409 into apache:main Jul 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants