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

davsclaus 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 604bc77eaa60 CAMEL-20997: camel-core - bound two test-thread waits, 
one of which can hang forever (#31073)
604bc77eaa60 is described below

commit 604bc77eaa60e5945d59edb74b644e318c7172e2
Author: dhairya05 <[email protected]>
AuthorDate: Mon Nov 30 14:02:45 2026 +0530

    CAMEL-20997: camel-core - bound two test-thread waits, one of which can 
hang forever (#31073)
    
    Both are waits on the test thread, the case that actually hangs a CI job
    since nothing else bounds them.
    
    DefaultEndpointRegistryTest#testConcurrency counts down outside any
    try/finally, and submit() swallows the exception into a Future nobody reads.
    If one of the five requestBody calls throws, the worker never counts down 
and
    the test thread waits in await() forever -- 500 iterations x 4 threads, so
    2000 chances. It would surface as a job killed on the overall timeout, with
    the exception lost.
    
    Fixed all three parts: countDown moved into a finally, the throwable 
captured
    and rethrown as the cause of an AssertionError naming the iteration, and the
    wait bounded. The finally alone would have been wrong -- it stops the hang 
but
    lets a worker exception pass silently, leaving the test green while doing
    nothing.
    
    DefaultTracerTraceCounterConcurrencyTest already counts down in a finally, 
so
    it only hangs if sendBody never returns; its completion wait is bounded in 
the
    module's AssertJ style. The worker-side startGate there is left alone: it is
    released by the next statement and sits in the worker's own try/finally.
    
    FileLockClusteredRoutePolicyTest also has an unbounded wait but is not
    touched: RESULTS.add(id) follows it, so bounding it would record a node as
    successful after a timeout and turn a real failure green.
    
    Co-Authored-By: Claude <[email protected]>
---
 .../camel/impl/DefaultEndpointRegistryTest.java    | 46 +++++++++++++++-------
 .../DefaultTracerTraceCounterConcurrencyTest.java  |  5 ++-
 2 files changed, 35 insertions(+), 16 deletions(-)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultEndpointRegistryTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultEndpointRegistryTest.java
index 7511dd42efa3..e95fa30a33ae 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultEndpointRegistryTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultEndpointRegistryTest.java
@@ -19,7 +19,9 @@ package org.apache.camel.impl;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.FluentProducerTemplate;
@@ -184,30 +186,44 @@ public class DefaultEndpointRegistryTest {
         int nThreads = 4;
         ExecutorService executorService = 
Executors.newFixedThreadPool(nThreads);
         int iterations = 500;
+        AtomicReference<Throwable> failure = new AtomicReference<>();
 
         for (int j = 0; j < iterations; j++) {
             CountDownLatch allThreadCompletionSemaphore = new 
CountDownLatch(nThreads);
             for (int i = 0; i < nThreads; i++) {
 
                 executorService.submit(() -> {
-
-                    
producerTemplate.requestBody("controlbus:route?routeId=route1&action=ACTION_STATUS&loggingLevel=off",
 null,
-                            ServiceStatus.class);
-                    
producerTemplate.requestBody("controlbus:route?routeId=route2&action=ACTION_STATUS&loggingLevel=off",
 null,
-                            ServiceStatus.class);
-                    
producerTemplate.requestBody("controlbus:route?routeId=route3&action=ACTION_STATUS&loggingLevel=off",
 null,
-                            ServiceStatus.class);
-                    
producerTemplate.requestBody("controlbus:route?routeId=route4&action=ACTION_STATUS&loggingLevel=off",
 null,
-                            ServiceStatus.class);
-                    
producerTemplate.requestBody("controlbus:route?routeId=route5&action=ACTION_STATUS&loggingLevel=off",
 null,
-                            ServiceStatus.class);
-
-                    allThreadCompletionSemaphore.countDown();
-
+                    try {
+                        producerTemplate.requestBody(
+                                
"controlbus:route?routeId=route1&action=ACTION_STATUS&loggingLevel=off", null,
+                                ServiceStatus.class);
+                        producerTemplate.requestBody(
+                                
"controlbus:route?routeId=route2&action=ACTION_STATUS&loggingLevel=off", null,
+                                ServiceStatus.class);
+                        producerTemplate.requestBody(
+                                
"controlbus:route?routeId=route3&action=ACTION_STATUS&loggingLevel=off", null,
+                                ServiceStatus.class);
+                        producerTemplate.requestBody(
+                                
"controlbus:route?routeId=route4&action=ACTION_STATUS&loggingLevel=off", null,
+                                ServiceStatus.class);
+                        producerTemplate.requestBody(
+                                
"controlbus:route?routeId=route5&action=ACTION_STATUS&loggingLevel=off", null,
+                                ServiceStatus.class);
+                    } catch (Throwable t) {
+                        failure.compareAndSet(null, t);
+                    } finally {
+                        allThreadCompletionSemaphore.countDown();
+                    }
                 });
             }
 
-            allThreadCompletionSemaphore.await();
+            assertTrue(allThreadCompletionSemaphore.await(30, 
TimeUnit.SECONDS),
+                    "the worker threads did not finish iteration " + j);
+
+            Throwable thrown = failure.get();
+            if (thrown != null) {
+                throw new AssertionError("a worker threw during iteration " + 
j, thrown);
+            }
 
             assertNotNull(endpointRegistry.values().toArray());
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/DefaultTracerTraceCounterConcurrencyTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/DefaultTracerTraceCounterConcurrencyTest.java
index dbe9a3b9ecf7..c8337eb6f801 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/DefaultTracerTraceCounterConcurrencyTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/DefaultTracerTraceCounterConcurrencyTest.java
@@ -19,6 +19,7 @@ package org.apache.camel.processor;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
@@ -73,7 +74,9 @@ class DefaultTracerTraceCounterConcurrencyTest extends 
ContextTestSupport {
             }
             // release all threads at once to maximise contention
             startGate.countDown();
-            doneLatch.await();
+            assertThat(doneLatch.await(30, TimeUnit.SECONDS))
+                    .as("the worker threads did not finish sending")
+                    .isTrue();
         } finally {
             pool.shutdown();
         }

Reply via email to