[
https://issues.apache.org/jira/browse/CAMEL-25342?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18124508#comment-18124508
]
Guillaume Nodet commented on CAMEL-25342:
-----------------------------------------
Fix implemented in PR #27505: https://github.com/apache/camel/pull/27505
*Root cause:* {{NatsConsumer.doStart()}} submits the NATS subscription
asynchronously via {{executor.submit(new NatsConsumingTask(...))}}. The method
returns before the subscription is established on the server. Since standard
NATS has no message persistence, the test's {{template.sendBody()}} call could
race ahead of {{dispatcher.subscribe()}} completing in the background thread,
causing the message to be silently dropped. The previous
{{setAssertPeriod(5000)}} workaround addressed false positives but not the
fundamental race.
*Fix:* Add an Awaitility wait on {{NatsConsumer.isActive()}} before sending the
message. {{setActive(true)}} is called at the end of
{{setupStandardNatsConsumer()}} after {{dispatcher.subscribe()}} completes,
making it the correct readiness signal. This mirrors the identical pattern
already established in {{NatsConsumerWithRedeliveryIT}}.
> Fix flaky test NatsConsumerIT
> -----------------------------
>
> Key: CAMEL-25342
> URL: https://issues.apache.org/jira/browse/CAMEL-25342
> Project: Camel
> Issue Type: Test
> Components: camel-nats
> Affects Versions: 4.23.0
> Reporter: Aurélien Pupier
> Assignee: Guillaume Nodet
> Priority: Major
>
> [2 failures and 1à flaky in last 90
> days|https://develocity.apache.org/scans/tests?search.relativeStartTime=P90D&search.rootProjectNames=camel&search.timeZoneId=Europe%2FParis&tests.container=org.apache.camel.component.nats.integration.NatsConsumerIT&tests.test=testConsumer]
>
> {noformat}
> java.lang.AssertionError: mock://result Received message count. Expected: <1>
> but was: <0>
> at
> org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:2075)
> at
> org.apache.camel.component.mock.MockEndpoint.assertEquals(MockEndpoint.java:2010)
>
> at
> org.apache.camel.component.mock.MockEndpoint.doAssertIsSatisfied(MockEndpoint.java:498)
>
> at
> org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:476)
>
> at
> org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:466)
>
> at
> org.apache.camel.component.nats.integration.NatsConsumerIT.testConsumer(NatsConsumerIT.java:38)
>
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)