oscerd opened a new pull request, #27013: URL: https://github.com/apache/camel/pull/27013
## Backport of #26855 Cherry-pick of #26855 onto `camel-4.22.x`. **Original PR:** #26855 - CAMEL-24957: Fix flaky test MessageHistoryExceptionRouteTest **Original author:** @tmielke **Target branch:** `camel-4.22.x` ### Why it is needed on 4.22.x On `camel-4.22.x`, PR CI tests every module that depends on a changed core module. So a core backport runs `camel-opentelemetry-metrics`, and there `MessageHistoryExceptionRouteTest.testMetricsHistory` fails all three surefire attempts: - first `expected: <5> but was: <4>` - then `ConditionTimeout` on both reruns These are exactly the two failure modes #26855 fixed on `main`. It currently blocks #26895, the 4.22.x backport of CAMEL-24973 (run 36427587057), and will block any other core backport to this branch. The cherry-pick applied cleanly, and its diff is identical to #26855's. It is test code only, in `AbstractOpenTelemetryTestSupport` and `MessageHistoryExceptionRouteTest`. Verified on `camel-4.22.x`: - full reactor `mvn clean install -DskipTests -DskipITs`: green - camel-opentelemetry-metrics module tests: 89 unit tests and 5 ITs green, `MessageHistoryExceptionRouteTest` included ### Original description Fixes two distinct failure modes in `MessageHistoryExceptionRouteTest.testMetricsHistory()`. **Failure 1 — Race condition (`expected: <5> but was: <4>`):** Metric recording via `nodeProcessingDone()` happens asynchronously on seda threads. `MockEndpoint.assertIsSatisfied()` only waits for mock endpoints to receive messages, not for metrics to be flushed. The bare `assertEquals()` calls could run before all `nodeProcessingDone()` callbacks had fired. Fix: wrap all metric count assertions in a single `await().untilAsserted()` block. **Failure 2 — Cleanup failure on rerun (`ConditionTimeoutException`):** `CamelOpenTelemetryExtension` implements `BeforeEachCallback` and `AfterEachCallback`, but the `otelExtension` field in `AbstractOpenTelemetryTestSupport` was missing `@RegisterExtension`, so JUnit never invoked those lifecycle methods. On a test retry in the same JVM the SDK was neither reset nor reinitialized, causing metrics to be undetectable. Fix: add `@RegisterExtension` to `otelExtension` in `AbstractOpenTelemetryTestSupport`. _Claude Code on behalf of @oscerd_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
