apupier commented on code in PR #30787:
URL: https://github.com/apache/camel/pull/30787#discussion_r4695650156


##########
components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsConsumerPushConsumerDeletedTest.java:
##########
@@ -251,6 +253,47 @@ void 
removesItsConnectionListenerWhenTheRouteStopsWhileItSubscribes() throws Exc
                 () -> assertEquals(List.of(), server.listeners, "no keeper 
listens to the connection after the stop"));
     }
 
+    @Test
+    void aDisconnectWaitsUntilTheConsumerListensToTheConnection() throws 
Exception {
+        // the consumer subscribes on its own executor and listens to the 
connection once the subscribe returned: hold
+        // that back, to force what a busy CI machine does (a disconnect while 
the consumer is still subscribing)
+        CountDownLatch subscribed = new CountDownLatch(1);
+        CountDownLatch release = new CountDownLatch(1);
+        // the route of the test may still be subscribing: wait for it, so 
that the hook below applies to the route
+        // that replaces it
+        await().atMost(10, TimeUnit.SECONDS).until(() -> 
!server.listeners.isEmpty());
+        server.beforeAddListener = () -> {
+            server.beforeAddListener = null;
+            subscribed.countDown();
+            try {
+                release.await(30, TimeUnit.SECONDS);
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+            }
+        };
+        consumeWith("exceptionHandler=#handler");
+        assertTrue(subscribed.await(30, TimeUnit.SECONDS), "the consumer 
subscribed");
+
+        Thread disconnecting = new Thread(server::disconnect, "disconnecting");
+        disconnecting.start();
+        // the disconnect must wait for the listener, else it deletes the 
consumer that is being subscribed and the
+        // reconnect reaches nobody
+        await().atMost(10, TimeUnit.SECONDS)
+                .until(() -> disconnecting.getState() == 
Thread.State.TIMED_WAITING);

Review Comment:
   Agreed, thanks. Fixed in c9d3acb2071e: FakeServer.disconnect() now counts 
down a latch (disconnectWaiting) as its first step and the test waits on it 
instead of reading the thread state. It then checks that the server stays 
connected for 2 seconds (Awaitility during + explicit atMost) and that the 
disconnecting thread is still alive, before releasing the listener. The test 
still fails without the wait in disconnect().
   
   _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