This is an automated email from the ASF dual-hosted git repository.

apupier pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new daff6da81e50 CAMEL-27512: camel-mongodb - fix flaky 
MongoDbConsumerStopTest
daff6da81e50 is described below

commit daff6da81e508a786cf4d5ef2f9f8d946eec2293
Author: AurĂ©lien Pupier <[email protected]>
AuthorDate: Tue Nov 24 13:31:17 2026 +0100

    CAMEL-27512: camel-mongodb - fix flaky MongoDbConsumerStopTest
    
    The stop of the consumer interrupts a consumer thread that is blocked
    reading the cursor, then returns right away. The thread sets
    interruptedWhileReading only once it wakes up from that interrupt, so
    the test, which asserted the flag as soon as the stop returned, sometimes
    read it before the thread set it and failed with "the consumer thread
    left behind is interrupted ==> expected: <true> but was: <false>".
    
    Wait for the flag with Awaitility (explicit atMost) instead of asserting
    it immediately. The production code is unchanged: the stop behaves as
    documented.
    
    Verified by delaying the setting of the flag by 300 millis in the
    simulated read: the former assertion then failed in the tailable and the
    change streams tests, and the waiting assertion passes.
    
    Co-authored-by: IBM Bob 2.2.1
---
 .../org/apache/camel/component/mongodb/MongoDbConsumerStopTest.java   | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git 
a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbConsumerStopTest.java
 
b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbConsumerStopTest.java
index 0ffad0e4472f..1293cce3d662 100644
--- 
a/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbConsumerStopTest.java
+++ 
b/components/camel-mongodb/src/test/java/org/apache/camel/component/mongodb/MongoDbConsumerStopTest.java
@@ -247,7 +247,9 @@ class MongoDbConsumerStopTest {
 
         assertNull(failure.get());
         assertEquals(ServiceStatus.Stopped, 
context.getRouteController().getRouteStatus("mongo"));
-        assertTrue(interruptedWhileReading.get(), "the consumer thread left 
behind is interrupted");
+        // the stop returns once it interrupted the thread, which sets the 
flag when it wakes up from the interrupt
+        await("the consumer thread left behind is interrupted").atMost(10, 
TimeUnit.SECONDS)
+                .until(interruptedWhileReading::get);
         List<String> warnings = events.stream().filter(e -> e.getLevel() == 
Level.WARN)
                 .map(e -> e.getMessage().getFormattedMessage()).toList();
         assertEquals(1, warnings.size(), "one WARN for the consumer thread 
left behind: " + warnings);

Reply via email to