You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@artemis.apache.org by cl...@apache.org on 2026/09/10 17:09:23 UTC

(artemis) 10/11: fixing flaky test from 'Improve Core connection handshake'

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/artemis.git

commit e5d278eac79118eb46074f1c2b7ee974af2d7838
Author: Clebert Suconic <cl...@gmail.com>
AuthorDate: Tue Aug 18 12:35:12 2026 -0400

    fixing flaky test from 'Improve Core connection handshake'
    
    (cherry picked from commit 8109e0adb4ec9aaf081bb617c518bebc07ce4fc0)
---
 .../core/impl/ActiveMQPacketHandlerTest.java         | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/protocol/core/impl/ActiveMQPacketHandlerTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/protocol/core/impl/ActiveMQPacketHandlerTest.java
index 762898ebc0..9a0d56d70e 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/protocol/core/impl/ActiveMQPacketHandlerTest.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/protocol/core/impl/ActiveMQPacketHandlerTest.java
@@ -17,6 +17,7 @@
 package org.apache.activemq.artemis.core.protocol.core.impl;
 
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.ArgumentMatchers.isNull;
@@ -54,6 +55,7 @@ public class ActiveMQPacketHandlerTest {
 
    private ActiveMQServer server;
    private Channel channel1;
+   private CountDownLatch closedLatch;
    private CoreRemotingConnection connection;
    private CoreProtocolManager protocolManager;
    private SecurityStore securityStore;
@@ -75,6 +77,13 @@ public class ActiveMQPacketHandlerTest {
       when(server.getVersion()).thenReturn(version);
       when(server.getNodeID()).thenReturn(SimpleString.of("test-node"));
       when(server.getHAPolicy()).thenReturn(mock(HAPolicy.class));
+
+      closedLatch = new CountDownLatch(1);
+
+      doAnswer((Answer<Void>) inv -> {
+         closedLatch.countDown();
+         return null;
+      }).when(connection).close();
    }
 
    /**
@@ -180,6 +189,7 @@ public class ActiveMQPacketHandlerTest {
       verify(channel1).sendAndFlush(captor.capture());
       assertInstanceOf(ActiveMQSecurityException.class, captor.getValue().getException(),
          "exception message must carry an ActiveMQSecurityException");
+      assertTrue(closedLatch.await(LATCH_TIMEOUT_MS, TimeUnit.MILLISECONDS));
       verify(connection).close();
       verify(channel1, never()).send(any(ConnectResponseMessage.class));
    }
@@ -206,6 +216,7 @@ public class ActiveMQPacketHandlerTest {
       verify(channel1).sendAndFlush(captor.capture());
       assertInstanceOf(ActiveMQSecurityException.class, captor.getValue().getException(),
          "exception message must carry an ActiveMQSecurityException");
+      assertTrue(closedLatch.await(LATCH_TIMEOUT_MS, TimeUnit.MILLISECONDS));
       verify(connection).close();
       verify(channel1, never()).send(any(ConnectResponseMessage.class));
    }
@@ -220,20 +231,13 @@ public class ActiveMQPacketHandlerTest {
 
       // Two packets: first latch counts down on the response, second triggers connection.close()
       CountDownLatch responseLatch = countdownOnChannelSend();
-      CountDownLatch closeLatch = new CountDownLatch(1);
-      doAnswer((Answer<Void>) inv -> {
-         closeLatch.countDown();
-         return null;
-      }).when(connection).close();
-
       ConnectMessage msg = new ConnectMessage("test-node", 1);
       ActiveMQPacketHandler handler = newHandler();
       handler.handlePacket(msg);
       responseLatch.await(LATCH_TIMEOUT_MS, TimeUnit.MILLISECONDS);
 
       handler.handlePacket(msg);
-      closeLatch.await(LATCH_TIMEOUT_MS, TimeUnit.MILLISECONDS);
-
+      assertTrue(closedLatch.await(LATCH_TIMEOUT_MS, TimeUnit.MILLISECONDS));
       verify(channel1).send(any(ConnectResponseMessage.class));
       verify(connection).close();
    }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@artemis.apache.org
For additional commands, e-mail: commits-help@artemis.apache.org