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/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new 6d0a9b57fa NO-JIRA Test improvement
6d0a9b57fa is described below

commit 6d0a9b57fac2bf9866dc717346fb7a26e398d17c
Author: Clebert Suconic <[email protected]>
AuthorDate: Mon Apr 28 14:57:55 2025 -0400

    NO-JIRA Test improvement
    
    I have seen a subsequent test failing with a thread leak.
    Just improving shutdown of executors (just in case) to make sure it is not 
an issue.
---
 .../failover/QuorumVoteServerConnectTest.java      | 167 ++++++++++-----------
 1 file changed, 82 insertions(+), 85 deletions(-)

diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/QuorumVoteServerConnectTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/QuorumVoteServerConnectTest.java
index 009b491c9d..b535da8d91 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/QuorumVoteServerConnectTest.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/QuorumVoteServerConnectTest.java
@@ -107,32 +107,31 @@ public class QuorumVoteServerConnectTest extends 
ActiveMQTestBase {
       assertFalse(quorum.getDecision());
       CountDownLatch taskStarted = new CountDownLatch(1);
       ExecutorService executor = Executors.newSingleThreadExecutor();
-      try {
-         final Future<InterruptedException> waitingTaskResult = 
executor.submit(() -> {
-            taskStarted.countDown();
-            try {
-               quorum.await(1, TimeUnit.DAYS);
-               return null;
-            } catch (InterruptedException e) {
-               return e;
-            }
-         });
-         // realistic expectation of the max time to start a Thread
-         assertTrue(taskStarted.await(10, TimeUnit.SECONDS));
-         assertFalse(waitingTaskResult.isDone());
-         quorum.allVotesCast(null);
+      runAfter(executor::shutdownNow);
+      final Future<InterruptedException> waitingTaskResult = 
executor.submit(() -> {
+         taskStarted.countDown();
          try {
-            assertNull(waitingTaskResult.get(5, TimeUnit.SECONDS));
-         } catch (TimeoutException ex) {
-            fail("allVoteCast hasn't unblocked the waiting task");
-         } catch (ExecutionException ex) {
-            fail("This shouldn't really happen: the wait task shouldn't throw 
any exception: " + ex);
+            quorum.await(1, TimeUnit.MINUTES);
+            return null;
+         } catch (InterruptedException e) {
+            // preserve interrupt state
+            Thread.currentThread().interrupt();
+            return e;
          }
-         assertTrue(waitingTaskResult.isDone());
-         assertFalse(quorum.getDecision());
-      } finally {
-         executor.shutdownNow();
+      });
+      // realistic expectation of the max time to start a Thread
+      assertTrue(taskStarted.await(10, TimeUnit.SECONDS));
+      assertFalse(waitingTaskResult.isDone());
+      quorum.allVotesCast(null);
+      try {
+         assertNull(waitingTaskResult.get(5, TimeUnit.SECONDS));
+      } catch (TimeoutException ex) {
+         fail("allVoteCast hasn't unblocked the waiting task");
+      } catch (ExecutionException ex) {
+         fail("This shouldn't really happen: the wait task shouldn't throw any 
exception: " + ex);
       }
+      assertTrue(waitingTaskResult.isDone());
+      assertFalse(quorum.getDecision());
    }
 
    @TestTemplate
@@ -145,40 +144,39 @@ public class QuorumVoteServerConnectTest extends 
ActiveMQTestBase {
       assertFalse(quorum.getDecision());
       CountDownLatch taskStarted = new CountDownLatch(1);
       ExecutorService executor = Executors.newSingleThreadExecutor();
-      try {
-         final Future<InterruptedException> waitingTaskResult = 
executor.submit(() -> {
-            taskStarted.countDown();
-            try {
-               quorum.await(1, TimeUnit.DAYS);
-               return null;
-            } catch (InterruptedException e) {
-               return e;
-            }
-         });
-         // realistic expectation of the max time to start a Thread
-         assertTrue(taskStarted.await(10, TimeUnit.SECONDS));
-         quorum.vote(new ServerConnectVote("foo", true, backupConnector));
-         assertFalse(waitingTaskResult.isDone());
-         assertFalse(quorum.getDecision());
-         for (int i = 0; i < trueVotes - 1; i++) {
-            quorum.vote(new ServerConnectVote("foo", true, connector));
-            assertFalse(waitingTaskResult.isDone());
-            assertFalse(quorum.getDecision());
-         }
-         quorum.vote(new ServerConnectVote("foo", true, connector));
-         assertTrue(quorum.getDecision());
+      runAfter(executor::shutdownNow);
+      final Future<InterruptedException> waitingTaskResult = 
executor.submit(() -> {
+         taskStarted.countDown();
          try {
-            assertNull(waitingTaskResult.get(5, TimeUnit.SECONDS));
-         } catch (TimeoutException ex) {
-            fail("allVoteCast hasn't unblocked the waiting task");
-         } catch (ExecutionException ex) {
-            fail("This shouldn't really happen: the wait task shouldn't throw 
any exception: " + ex);
+            quorum.await(1, TimeUnit.MINUTES);
+            return null;
+         } catch (InterruptedException e) {
+            // preserve interrupt state
+            Thread.currentThread().interrupt();
+            return e;
          }
-         assertTrue(waitingTaskResult.isDone());
-         assertTrue(quorum.getDecision());
-      } finally {
-         executor.shutdownNow();
+      });
+      // realistic expectation of the max time to start a Thread
+      assertTrue(taskStarted.await(10, TimeUnit.SECONDS));
+      quorum.vote(new ServerConnectVote("foo", true, backupConnector));
+      assertFalse(waitingTaskResult.isDone());
+      assertFalse(quorum.getDecision());
+      for (int i = 0; i < trueVotes - 1; i++) {
+         quorum.vote(new ServerConnectVote("foo", true, connector));
+         assertFalse(waitingTaskResult.isDone());
+         assertFalse(quorum.getDecision());
+      }
+      quorum.vote(new ServerConnectVote("foo", true, connector));
+      assertTrue(quorum.getDecision());
+      try {
+         assertNull(waitingTaskResult.get(5, TimeUnit.SECONDS));
+      } catch (TimeoutException ex) {
+         fail("allVoteCast hasn't unblocked the waiting task");
+      } catch (ExecutionException ex) {
+         fail("This shouldn't really happen: the wait task shouldn't throw any 
exception: " + ex);
       }
+      assertTrue(waitingTaskResult.isDone());
+      assertTrue(quorum.getDecision());
    }
 
    @TestTemplate
@@ -189,40 +187,39 @@ public class QuorumVoteServerConnectTest extends 
ActiveMQTestBase {
       assertFalse(quorum.getDecision());
       CountDownLatch taskStarted = new CountDownLatch(1);
       ExecutorService executor = Executors.newSingleThreadExecutor();
-      try {
-         final Future<InterruptedException> waitingTaskResult = 
executor.submit(() -> {
-            taskStarted.countDown();
-            try {
-               quorum.await(1, TimeUnit.DAYS);
-               return null;
-            } catch (InterruptedException e) {
-               return e;
-            }
-         });
-         // realistic expectation of the max time to start a Thread
-         assertTrue(taskStarted.await(10, TimeUnit.SECONDS));
-         quorum.vote(new ServerConnectVote("foo", false, null));
-         assertFalse(waitingTaskResult.isDone());
-         assertFalse(quorum.getDecision());
-         for (int i = 0; i < trueVotes - 1; i++) {
-            quorum.vote(new ServerConnectVote("foo", true, null));
-            assertFalse(waitingTaskResult.isDone());
-            assertFalse(quorum.getDecision());
-         }
-         quorum.vote(new ServerConnectVote("foo", true, null));
-         assertTrue(quorum.getDecision());
+      runAfter(executor::shutdownNow);
+      final Future<InterruptedException> waitingTaskResult = 
executor.submit(() -> {
+         taskStarted.countDown();
          try {
-            assertNull(waitingTaskResult.get(5, TimeUnit.SECONDS));
-         } catch (TimeoutException ex) {
-            fail("allVoteCast hasn't unblocked the waiting task");
-         } catch (ExecutionException ex) {
-            fail("This shouldn't really happen: the wait task shouldn't throw 
any exception: " + ex);
+            quorum.await(1, TimeUnit.MINUTES);
+            return null;
+         } catch (InterruptedException e) {
+            // preserve interrupt state
+            Thread.currentThread().interrupt();
+            return e;
          }
-         assertTrue(waitingTaskResult.isDone());
-         assertTrue(quorum.getDecision());
-      } finally {
-         executor.shutdownNow();
+      });
+      // realistic expectation of the max time to start a Thread
+      assertTrue(taskStarted.await(10, TimeUnit.SECONDS));
+      quorum.vote(new ServerConnectVote("foo", false, null));
+      assertFalse(waitingTaskResult.isDone());
+      assertFalse(quorum.getDecision());
+      for (int i = 0; i < trueVotes - 1; i++) {
+         quorum.vote(new ServerConnectVote("foo", true, null));
+         assertFalse(waitingTaskResult.isDone());
+         assertFalse(quorum.getDecision());
       }
+      quorum.vote(new ServerConnectVote("foo", true, null));
+      assertTrue(quorum.getDecision());
+      try {
+         assertNull(waitingTaskResult.get(5, TimeUnit.SECONDS));
+      } catch (TimeoutException ex) {
+         fail("allVoteCast hasn't unblocked the waiting task");
+      } catch (ExecutionException ex) {
+         fail("This shouldn't really happen: the wait task shouldn't throw any 
exception: " + ex);
+      }
+      assertTrue(waitingTaskResult.isDone());
+      assertTrue(quorum.getDecision());
    }
 
    @TestTemplate


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to