apupier opened a new pull request, #30787:
URL: https://github.com/apache/camel/pull/30787

   NatsConsumerPushConsumerDeletedTest is still flaky on CI after the first
   fix (apache/camel#28614). The failures seen:
   
   - mock://result Received message count. Expected: <1|2> but was: <0> in
     consumesAgainAfterTheServerDeletedTheEphemeralConsumer,
     resumesAnEphemeralConsumerThatStartedAtATime and
     consumesAStreamCreatedAgainFromItsStart
   - "the consumer keeps checking, 0 ==> expected: <true> but was: <false>"
     in keepsCheckingUntilTheStreamIsCreatedAgain
   - "the subscription made while the route stopped is ended ==> expected:
     <true> but was: <false>" in endsTheSubscriptionItMadeWhileTheRouteStopped
   
   Cause: the consumer subscribes on its own executor (doStart() submits the
   task), and NatsJetStreamPushConsumerKeeper registers its connection
   listener only once that subscribe returned. The test route consumes the
   first message from the dispatcher thread, which can happen before that,
   so mock.assertIsSatisfied() of the first message can pass while the
   keeper is not listening yet. The test then calls FakeServer.disconnect()
   and reconnect():
   
   - disconnect() marks the consumers deleted, including the one that is
     still being subscribed, and
   - reconnect() fires RESUBSCRIBED to an empty listener list, so no keeper
     checks the consumer and nobody subscribes again.
   
   The test then waits for messages (or for checks of the consumer) that
   never come, and times out. This is a race of the test, not of the
   production code: with a real connection jnats keeps the listeners
   registered, and the keeper always sees the reconnect once it is started.
   The first fix waited for the listener only in two tests; every other test
   that calls disconnect() had the same race.
   
   Fix (test only, no production change): FakeServer.disconnect() waits,
   with an Awaitility wait with an explicit atMost of 30 seconds, until a
   connection listener is registered before it disconnects, so that every
   test that disconnects is covered. The state change moves to the private
   doDisconnect(). Nothing changes for a test where the listener is there
   already.
   
   New test aDisconnectWaitsUntilTheConsumerListensToTheConnection forces
   the race instead of hoping for a slow machine: a beforeAddListener hook
   of the fake connection holds the consumer between its subscribe and the
   registration of its listener, on a latch. The test then disconnects on
   another thread, checks that the disconnect waits (the server is still
   connected), releases the latch, and checks that after publish and
   reconnect the message is consumed, i.e. the keeper checked the consumer.
   
   Verification (mvn -o test -Dtest=NatsConsumerPushConsumerDeletedTest in
   components/camel-nats on the local machine):
   
   - the race could not be reproduced by repeating the tests on an idle
     machine, so it was widened: a 2 second sleep in addConnectionListener
     of the fake connection (temporary, not committed).
     - without the fix: 10 of the 13 tests failed (8 failures and 2 errors,
       the same on the surefire rerun), with the messages above, in about
       218 seconds
     - with the fix: 13 of 13 passed
   - new test without the wait in disconnect(): fails with a
     ConditionTimeout, as the disconnect does not wait for the listener
   - with the fix: 14 of 14 tests passed in 3 runs on an idle machine, in
     3 runs with every CPU busy (13 tests at that time), and in 2 more runs
     after the last change
   
   
   JIRA: https://issues.apache.org/jira/browse/CAMEL-26366
   
   _Bob (IBM Bob 2.2.1) on behalf of @apupier_
   


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