You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2026/07/06 08:26:24 UTC

[PR] CAMEL-23918: Fix flaky tests in camel-reactive-streams [camel]

gnodet opened a new pull request, #24448:
URL: https://github.com/apache/camel/pull/24448

   ## Summary
   
   Replace `Thread.sleep` calls with Awaitility-based assertions and Camel-idiomatic alternatives across 5 test classes in `camel-reactive-streams`:
   
   - **DelayedMonoPublisherTest** (5 sleeps): Use `ScheduledExecutorService.schedule()` for delayed actions and Awaitility `await().until()` for condition-based waiting
   - **BackpressureStrategyTest** (6 sleeps): Use `AtomicInteger` counter with Awaitility to reliably wait for timer events, replacing fixed sleep durations
   - **BackpressureSubscriberTest** (3 sleeps): Replace `Thread.sleep` in route processors with Camel's `delay()` EIP for simulating processing time
   - **BackpressurePublisherRoutePolicyTest** (2 sleeps): Use Awaitility `untilAsserted()` to wait for route policy state changes
   - **BasicPublisherTest** (1 sleep): Remove unnecessary sleep between dispose/subscribe
   
   Also adds the Awaitility test dependency to the module's `pom.xml`.
   
   ## Test plan
   
   - [x] All 65 tests in `camel-reactive-streams` pass locally
   - [x] No remaining `Thread.sleep` calls in the 5 affected test files
   - [ ] CI build passes
   
   _Claude Code on behalf of Guillaume Nodet_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23918: Fix flaky tests in camel-reactive-streams [camel]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #24448:
URL: https://github.com/apache/camel/pull/24448#issuecomment-4891528912

   _Claude Code on behalf of Guillaume Nodet_
   
   Closing — this fix was not validated by running the test 100 times first. Will re-dispatch with a validation-first approach: run the test 100x, and only create a JIRA + fix if it actually fails.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23918: Fix flaky tests in camel-reactive-streams [camel]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #24448:
URL: https://github.com/apache/camel/pull/24448#issuecomment-4891201878

   _Claude Code on behalf of Guillaume Nodet_
   
   📋 **Process note**: Before undrafting, the test(s) modified in this PR should be run 100 times (e.g. with `mvn test -Dsurefire.rerunFailingTestsCount=0 -Dtest=<TestClass> -pl <module> -Dsurefire.runCount=100`) to confirm they are actually flaky. If they pass 100/100 without the fix, the change may not be needed.
   
   Also ensure:
   - MockEndpoint helpers (`assertIsSatisfied()` already waits 10s, `setResultWaitTime()`, `setAssertPeriod()`) are used where appropriate instead of Awaitility wrappers
   - Valid `Thread.sleep()` calls (UDP pacing, simulation delays, "wait to confirm nothing happens") are preserved


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23918: Fix flaky tests in camel-reactive-streams [camel]

Posted by "apupier (via GitHub)" <gi...@apache.org>.
apupier commented on code in PR #24448:
URL: https://github.com/apache/camel/pull/24448#discussion_r3527479761


##########
components/camel-reactive-streams/src/test/java/org/apache/camel/component/reactive/streams/BackpressureStrategyTest.java:
##########
@@ -145,12 +155,14 @@ public void onNext(Integer o) {
         context().start();
 
         assertTrue(latch.await(5, TimeUnit.SECONDS));
-        Thread.sleep(1000); // wait for all numbers to be generated
+        // Wait for all 20 timer events to be processed
+        await().atMost(5, TimeUnit.SECONDS).until(() -> timerCount.get() >= 20);
 
         subscriber.request(19);
-        assertTrue(latch2.await(1, TimeUnit.SECONDS));
-        Thread.sleep(200); // add other time to ensure no other items arrive
-        assertEquals(2, queue.size());
+        assertTrue(latch2.await(2, TimeUnit.SECONDS));
+        // Verify exactly 2 items received and no more arrive
+        await().atMost(2, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertEquals(2, queue.size()));

Review Comment:
   this is no more waiting for potential new messages erroneously to arrive



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23918: Fix flaky tests in camel-reactive-streams [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #24448:
URL: https://github.com/apache/camel/pull/24448#issuecomment-4891230124

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `components/camel-reactive-streams`
   
   ---
   
   <details><summary>:microscope: Scalpel shadow comparison — Scalpel: 11 tested, 29 compile-only — current: 11 all tested</summary>
   
   [Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **40 affected modules** (current approach: 11).
   
   <details><summary>:warning: Modules only in Scalpel (29)</summary>
   
   - `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`
   
   </details>
   
   **Skip-tests mode would test 11 modules** (1 direct + 10 downstream), **skip tests for 29** (generated code, meta-modules)
   
   <details><summary>Modules Scalpel would test (11)</summary>
   
   - `camel-jbang-mcp`
   - `camel-jbang-plugin-mcp`
   - `camel-jbang-plugin-route-parser`
   - `camel-jbang-plugin-tui`
   - `camel-jbang-plugin-validate`
   - `camel-launcher-container`
   - `camel-reactive-streams`
   - `camel-reactor`
   - `camel-rxjava`
   - `camel-yaml-dsl-validator`
   - `camel-yaml-dsl-validator-maven-plugin`
   
   </details>
   
   <details><summary>Modules with tests skipped (29)</summary>
   
   - `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`
   
   </details>
   
   > :information_source: Shadow mode — Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
   
   </details>
   
   <details><summary>All tested modules (40 modules)</summary>
   
   - 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 :: Reactive Streams
   - Camel :: Reactor
   - Camel :: RxJava
   - Camel :: YAML DSL
   - Camel :: YAML DSL :: Deserializers
   - Camel :: YAML DSL :: Maven Plugins
   - Camel :: YAML DSL :: Validator
   - Camel :: YAML DSL :: Validator Maven Plugin
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/28778153939)


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23918: Fix flaky tests in camel-reactive-streams [camel]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #24448:
URL: https://github.com/apache/camel/pull/24448#issuecomment-4891952537

   @copilot review


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23918: Fix flaky tests in camel-reactive-streams [camel]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet closed pull request #24448: CAMEL-23918: Fix flaky tests in camel-reactive-streams
URL: https://github.com/apache/camel/pull/24448


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23918: Fix flaky tests in camel-reactive-streams [camel]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #24448:
URL: https://github.com/apache/camel/pull/24448#issuecomment-4891010367

   @copilot review


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23918: Fix flaky tests in camel-reactive-streams [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #24448:
URL: https://github.com/apache/camel/pull/24448


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23918: Fix flaky tests in camel-reactive-streams [camel]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #24448:
URL: https://github.com/apache/camel/pull/24448#issuecomment-4891898469

   ### Third commit: Fix race condition in BackpressureStrategyTest
   
   Investigation revealed a pre-existing race condition in `BackpressureStrategyTest` that caused the exact-sum assertions to fail non-deterministically (even without `Thread.sleep`).
   
   **Root cause**: `CamelSubscription.checkAndFlush()` schedules the flush asynchronously on a worker pool thread. With the timer firing every 20ms, the next item can arrive and modify the buffer (via the backpressure strategy) before the flush actually runs:
   
   - **OLDEST**: Item 1 enters buffer → Item 2 arrives before flush → OLDEST discards item 2 (keeps oldest) → flush delivers item 1 → item 3 becomes the new oldest → result: [1, 3] sum=4 instead of [1, 2] sum=3
   - **LATEST**: Item 1 enters buffer → Item 2 arrives before flush → LATEST replaces item 1 with item 2 → flush delivers item 2 → item 20 ends up as latest → result: [2, 20] sum=22 instead of [1, 20] sum=21
   
   **Fix**: Replace fragile exact-sum assertions with invariant-based assertions that verify the actual backpressure strategy behavior:
   - **OLDEST**: first item is always 1 (oldest kept in buffer), second item is an early value (>1, <20)
   - **LATEST**: second item is always 20 (most recent always kept by LATEST strategy)
   
   _Claude Code on behalf of Guillaume Nodet_


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23918: Fix flaky tests in camel-reactive-streams [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #24448:
URL: https://github.com/apache/camel/pull/24448#issuecomment-4890817903

   :star2: Thank you for your contribution to the Apache Camel project! :star2:
     :robot: CI automation will test this PR automatically.
   
     :camel: 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](https://camel.apache.org/community/team/#committers) have access to the summary.
     
     :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23918: Fix flaky tests in camel-reactive-streams [camel]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #24448:
URL: https://github.com/apache/camel/pull/24448#discussion_r3527658886


##########
components/camel-reactive-streams/src/test/java/org/apache/camel/component/reactive/streams/BackpressureStrategyTest.java:
##########
@@ -145,12 +155,14 @@ public void onNext(Integer o) {
         context().start();
 
         assertTrue(latch.await(5, TimeUnit.SECONDS));
-        Thread.sleep(1000); // wait for all numbers to be generated
+        // Wait for all 20 timer events to be processed
+        await().atMost(5, TimeUnit.SECONDS).until(() -> timerCount.get() >= 20);
 
         subscriber.request(19);
-        assertTrue(latch2.await(1, TimeUnit.SECONDS));
-        Thread.sleep(200); // add other time to ensure no other items arrive
-        assertEquals(2, queue.size());
+        assertTrue(latch2.await(2, TimeUnit.SECONDS));
+        // Verify exactly 2 items received and no more arrive
+        await().atMost(2, TimeUnit.SECONDS)
+                .untilAsserted(() -> assertEquals(2, queue.size()));

Review Comment:
   Good catch! Fixed in 2b503ed — replaced `await().untilAsserted()` with `await().during(500ms).until(() -> queue.size() == 2)` which verifies that the queue size remains stable at 2 for 500ms, ensuring no extra items erroneously arrive.
   
   _Claude Code on behalf of Guillaume Nodet_



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org