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

commit d9e938afdd596000ddb90e05f17efa16e5228557
Author: Torsten Mielke <[email protected]>
AuthorDate: Thu Sep 24 15:19:10 2026 +0200

    CAMEL-24957: Fix same race condition in MessageHistoryTest
    
    Apply the same await().untilAsserted() guard to the bare assertEquals()
    calls after MockEndpoint.assertIsSatisfied() in MessageHistoryTest.
    The seda: endpoints dispatch asynchronously, so metric recording via
    nodeProcessingDone() can lag behind mock receipt, causing the same
    'expected: <5> but was: <4>' flakiness as in 
MessageHistoryExceptionRouteTest.
    
    Co-authored-by: Claude Sonnet 4.5 <[email protected]>
---
 .../metrics/messagehistory/MessageHistoryTest.java     | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git 
a/components/camel-opentelemetry-metrics/src/test/java/org/apache/camel/opentelemetry/metrics/messagehistory/MessageHistoryTest.java
 
b/components/camel-opentelemetry-metrics/src/test/java/org/apache/camel/opentelemetry/metrics/messagehistory/MessageHistoryTest.java
index c821e7ad0e8d..400af4c070e3 100644
--- 
a/components/camel-opentelemetry-metrics/src/test/java/org/apache/camel/opentelemetry/metrics/messagehistory/MessageHistoryTest.java
+++ 
b/components/camel-opentelemetry-metrics/src/test/java/org/apache/camel/opentelemetry/metrics/messagehistory/MessageHistoryTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.opentelemetry.metrics.messagehistory;
 
+import java.util.concurrent.TimeUnit;
+
 import io.opentelemetry.api.common.AttributeKey;
 import io.opentelemetry.sdk.metrics.data.HistogramPointData;
 import io.opentelemetry.sdk.metrics.data.PointData;
@@ -26,6 +28,7 @@ import 
org.apache.camel.opentelemetry.metrics.AbstractOpenTelemetryTestSupport;
 import org.junit.jupiter.api.Test;
 
 import static 
org.apache.camel.opentelemetry.metrics.OpenTelemetryConstants.DEFAULT_CAMEL_MESSAGE_HISTORY_METER_NAME;
+import static org.awaitility.Awaitility.await;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -58,12 +61,15 @@ public class MessageHistoryTest extends 
AbstractOpenTelemetryTestSupport {
 
         MockEndpoint.assertIsSatisfied(context);
 
-        // there should be 3 names
-        assertEquals(3, 
getAllPointData(DEFAULT_CAMEL_MESSAGE_HISTORY_METER_NAME).size());
-
-        assertEquals(count / 2, getPointData("route1", "foo").getCount());
-        assertEquals(count / 2, getPointData("route2", "bar").getCount());
-        assertEquals(count / 2, getPointData("route2", "baz").getCount());
+        // Metric recording via nodeProcessingDone() happens asynchronously on 
seda threads,
+        // so all metric assertions need to be wrapped in await() to avoid a 
race with mock receipt.
+        await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
+            // there should be 3 names
+            assertEquals(3, 
getAllPointData(DEFAULT_CAMEL_MESSAGE_HISTORY_METER_NAME).size());
+            assertEquals(count / 2, getPointData("route1", "foo").getCount());
+            assertEquals(count / 2, getPointData("route2", "bar").getCount());
+            assertEquals(count / 2, getPointData("route2", "baz").getCount());
+        });
     }
 
     private HistogramPointData getPointData(String routeId, String nodeId) {

Reply via email to