oscerd commented on code in PR #27013:
URL: https://github.com/apache/camel/pull/27013#discussion_r4125236593


##########
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:
   Right, thanks, my mistake. #26855 was rebase-merged, so it landed on `main` 
as two commits, `36503c92` and `d9e938af` ("Fix same race condition in 
MessageHistoryTest"). I cherry-picked only the first. `d9e938af` is now 
cherry-picked as well, with a diff identical to `main`'s, so the backport now 
covers all three files of #26855. On `camel-4.22.x`, 
camel-opentelemetry-metrics passes 89 unit tests and 5 ITs 
(`MessageHistoryTest` and `MessageHistoryExceptionRouteTest` included), and the 
full reactor (`-DskipTests`) is green.
   
   _Claude Code on behalf of @oscerd_
   



-- 
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