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

brandonwilliams pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 2344e77  Fixed race condition in MoveTest by waiting for stale 
endpoints to be evicted from membership before starting another test.
2344e77 is described below

commit 2344e77c026f1ecfed4f9ba84dab21ede2cf5b26
Author: Gianluca Righetto <gianl...@menttis.com>
AuthorDate: Thu Apr 9 18:55:10 2020 -0300

    Fixed race condition in MoveTest by waiting for stale endpoints to be 
evicted from membership before starting another test.
    
    Patch by Gianluca Righetto, reviewed by brandonwilliams for CASSANDRA-15551.
---
 .../org/apache/cassandra/service/MoveTest.java     | 36 +++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/test/unit/org/apache/cassandra/service/MoveTest.java 
b/test/unit/org/apache/cassandra/service/MoveTest.java
index a4da7b8..9777602 100644
--- a/test/unit/org/apache/cassandra/service/MoveTest.java
+++ b/test/unit/org/apache/cassandra/service/MoveTest.java
@@ -21,10 +21,18 @@ package org.apache.cassandra.service;
 
 import java.net.UnknownHostException;
 import java.util.*;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.function.Consumer;
 
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Multimap;
+
+import org.apache.cassandra.config.OverrideConfigurationLoader;
+import org.apache.cassandra.diag.DiagnosticEventService;
+import org.apache.cassandra.gms.GossiperEvent;
 import org.apache.cassandra.locator.EndpointsForRange;
 import org.apache.cassandra.locator.EndpointsForToken;
 import org.apache.cassandra.locator.RangesAtEndpoint;
@@ -32,7 +40,11 @@ import org.apache.cassandra.locator.RangesByEndpoint;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TestRule;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
 
 import org.apache.cassandra.locator.InetAddressAndPort;
 import org.apache.cassandra.locator.Replica;
@@ -99,6 +111,7 @@ public class MoveTest
         addNetworkTopologyKeyspace(Network_11_KeyspaceName, 1, 1);
         addNetworkTopologyKeyspace(Network_22_KeyspaceName, 2, 2);
         addNetworkTopologyKeyspace(Network_33_KeyspaceName, 3, 3);
+        DatabaseDescriptor.setDiagnosticEventsEnabled(true);
     }
 
     @AfterClass
@@ -108,10 +121,31 @@ public class MoveTest
     }
 
     @Before
-    public void clearTokenMetadata()
+    public void clearTokenMetadata() throws InterruptedException
     {
+        // we expect to have a single endpoint before running each test method,
+        // so we have to wait for the GossipStage thread to evict stale 
endpoints
+        // from membership before moving on, otherwise it may break other 
tests as
+        // things change in the background
+        final int endpointCount = Gossiper.instance.getEndpointCount() - 1;
+        final CountDownLatch latch = new CountDownLatch(endpointCount);
+        Consumer onEndpointEvicted = event -> latch.countDown();
+        DiagnosticEventService.instance().subscribe(GossiperEvent.class,
+                                                    
GossiperEvent.GossiperEventType.EVICTED_FROM_MEMBERSHIP,
+                                                    onEndpointEvicted);
+
         PendingRangeCalculatorService.instance.blockUntilFinished();
         StorageService.instance.getTokenMetadata().clearUnsafe();
+
+        try
+        {
+            if (!latch.await(1, TimeUnit.MINUTES))
+                throw new RuntimeException("Took too long to evict stale 
endpoints.");
+        }
+        finally
+        {
+            DiagnosticEventService.instance().unsubscribe(onEndpointEvicted);
+        }
     }
 
     private static void addNetworkTopologyKeyspace(String keyspaceName, 
Integer... replicas) throws Exception


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to