You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2021/06/16 04:13:29 UTC

[james-project] 01/05: JAMES-3599 GroupContract::groupDeliveryShouldNotExceedRate is subject to data races

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

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit e217e641a74fbee2fa5cccbe4013ad3929971975
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Jun 14 15:06:56 2021 +0700

    JAMES-3599 GroupContract::groupDeliveryShouldNotExceedRate is subject to data races
    
    An assertions mixes two atomic integers, thus atomicity
    fails
---
 .../api/src/test/java/org/apache/james/events/GroupContract.java | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/event-bus/api/src/test/java/org/apache/james/events/GroupContract.java b/event-bus/api/src/test/java/org/apache/james/events/GroupContract.java
index 01eda24..69ab252 100644
--- a/event-bus/api/src/test/java/org/apache/james/events/GroupContract.java
+++ b/event-bus/api/src/test/java/org/apache/james/events/GroupContract.java
@@ -65,7 +65,7 @@ public interface GroupContract {
         default void groupDeliveryShouldNotExceedRate() {
             int eventCount = 50;
             AtomicInteger nbCalls = new AtomicInteger(0);
-            AtomicInteger finishedExecutions = new AtomicInteger(0);
+            AtomicInteger inFlight = new AtomicInteger(0);
             AtomicBoolean rateExceeded = new AtomicBoolean(false);
 
             eventBus().register(new EventListener.GroupEventListener() {
@@ -81,13 +81,12 @@ public interface GroupContract {
 
                 @Override
                 public void event(Event event) throws Exception {
-                    if (nbCalls.get() - finishedExecutions.get() > EventBus.EXECUTION_RATE) {
+                    if (inFlight.incrementAndGet() > EventBus.EXECUTION_RATE) {
                         rateExceeded.set(true);
                     }
                     nbCalls.incrementAndGet();
                     Thread.sleep(Duration.ofMillis(20).toMillis());
-                    finishedExecutions.incrementAndGet();
-
+                    inFlight.decrementAndGet();
                 }
             }, GROUP_A);
 
@@ -95,7 +94,7 @@ public interface GroupContract {
                 .forEach(i -> eventBus().dispatch(EVENT, NO_KEYS).block());
 
             getSpeedProfile().shortWaitCondition().atMost(TEN_MINUTES)
-                .untilAsserted(() -> assertThat(finishedExecutions.get()).isEqualTo(eventCount));
+                .untilAsserted(() -> assertThat(nbCalls.get()).isEqualTo(eventCount));
             assertThat(rateExceeded).isFalse();
         }
 

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org