You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2020/07/08 16:36:46 UTC

[activemq-artemis] 03/03: NO-JIRA Fixing rare intermittent failure on CreditsSemaphoreTest

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

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

commit c1be566c2036353274b6f45078a2a94a2e6eb54a
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Wed Jul 8 12:36:26 2020 -0400

    NO-JIRA Fixing rare intermittent failure on CreditsSemaphoreTest
---
 .../protocol/amqp/util/CreditsSemaphoreTest.java   | 29 +++++++++++++---------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/util/CreditsSemaphoreTest.java b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/util/CreditsSemaphoreTest.java
index d4e7805..dd74d4c 100644
--- a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/util/CreditsSemaphoreTest.java
+++ b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/util/CreditsSemaphoreTest.java
@@ -60,12 +60,7 @@ public class CreditsSemaphoreTest {
 
       Assert.assertEquals(0, semaphore.getCredits());
 
-      long timeout = System.currentTimeMillis() + 1000;
-      while (!semaphore.hasQueuedThreads() && System.currentTimeMillis() < timeout) {
-         Thread.sleep(10);
-      }
-
-      Assert.assertTrue(semaphore.hasQueuedThreads());
+      validateQueuedThreads();
 
       semaphore.setCredits(2);
 
@@ -76,6 +71,21 @@ public class CreditsSemaphoreTest {
       Assert.assertFalse(semaphore.hasQueuedThreads());
    }
 
+   private void validateQueuedThreads() throws InterruptedException {
+      boolean hasQueueThreads = false;
+      long timeout = System.currentTimeMillis() + 5000;
+      while (System.currentTimeMillis() < timeout) {
+
+         if (semaphore.hasQueuedThreads()) {
+            hasQueueThreads = true;
+            break;
+         }
+         Thread.sleep(10);
+      }
+
+      Assert.assertTrue(hasQueueThreads);
+   }
+
    @Test
    public void testDownAndUp() throws Exception {
       thread.start();
@@ -114,12 +124,7 @@ public class CreditsSemaphoreTest {
 
       Assert.assertEquals(0, semaphore.getCredits());
 
-      long timeout = System.currentTimeMillis() + 1000;
-      while (!semaphore.hasQueuedThreads() && System.currentTimeMillis() < timeout) {
-         Thread.sleep(10);
-      }
-
-      Assert.assertTrue(semaphore.hasQueuedThreads());
+      validateQueuedThreads();
 
       Assert.assertEquals(0, acquired.get());