[
https://issues.apache.org/jira/browse/CAMEL-25342?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18124497#comment-18124497
]
Guillaume Nodet commented on CAMEL-25342:
-----------------------------------------
This issue is being investigated by a coding agent (on behalf of gnodet).
*Root cause identified:* Classic publish-before-subscribe race condition in
testConsumer().
In NatsConsumer.doStart(), the NATS subscription is established
_asynchronously_ via executor.submit(new NatsConsumingTask(...)). The doStart()
method returns before the subscription is active on the NATS server. Since
standard NATS has no message persistence, the test send at line 35 can beat the
async subscribe() call, and the message is silently dropped.
The setAssertPeriod(5000) (commit 685e1a4eca3) addresses false positives but
not the fundamental race.
*Fix:* Wait for the consumer to be fully subscribed before sending.
NatsConsumer.setActive(true) is called after dispatcher.subscribe() completes,
so an Awaitility wait on isActive() before the send will eliminate the race.
_Note: This comment was generated by an AI coding agent and requires manual
verification._
> 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)