gnodet-bot commented on code in PR #27013:
URL: https://github.com/apache/camel/pull/27013#discussion_r4124885144


##########
components/camel-opentelemetry-metrics/src/test/java/org/apache/camel/opentelemetry/metrics/messagehistory/MessageHistoryExceptionRouteTest.java:
##########
@@ -61,13 +61,16 @@ public void testMetricsHistory() throws Exception {
 
         MockEndpoint.assertIsSatisfied(context);
 
-        // there should be 3 names for the message history (foo, bar, 
exception)
-        assertEquals(3, 
getAllPointData(DEFAULT_CAMEL_MESSAGE_HISTORY_METER_NAME).size());
-        assertEquals(5, getPointData("route1", "foo").getCount());
-        assertEquals(5, getPointData("route2", "bar").getCount());
-        // exception process node
-        await().atMost(5, TimeUnit.SECONDS)
-                .untilAsserted(() -> assertEquals(5, getPointData("route2", 
"process1").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 for the message history (foo, bar, 
process1)
+            assertEquals(3, 
getAllPointData(DEFAULT_CAMEL_MESSAGE_HISTORY_METER_NAME).size());
+            assertEquals(5, getPointData("route1", "foo").getCount());
+            assertEquals(5, getPointData("route2", "bar").getCount());
+            // exception process node
+            assertEquals(5, getPointData("route2", "process1").getCount());
+        });
     }
 
     private HistogramPointData getPointData(String routeId, String nodeId) {

Review Comment:
   ⚠️ **Incomplete cherry-pick:** The original PR #26855 applied this exact 
same `await().untilAsserted()` fix to `MessageHistoryTest.java` as well — same 
package, same async metric race. That file was not included in this cherry-pick.
   
   On `camel-4.22.x`, `MessageHistoryTest.testMessageHistory()` still has bare 
`assertEquals()` calls after `MockEndpoint.assertIsSatisfied()`, making it 
vulnerable to the same flaky failures this backport aims to fix.
   
   Please cherry-pick the `MessageHistoryTest.java` hunk from #26855 as well.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to