You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2020/10/26 17:14:50 UTC

[lucene-solr] branch branch_8x updated: Remove sleeps from SolrZkClientTest.testWrappingWatches (#1936)

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

tflobbe pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new 0ac7f4b  Remove sleeps from SolrZkClientTest.testWrappingWatches (#1936)
0ac7f4b is described below

commit 0ac7f4b3edbd051a0e017efbb36a843d633cb161
Author: Tomas Fernandez Lobbe <tf...@apache.org>
AuthorDate: Mon Oct 26 10:11:11 2020 -0700

    Remove sleeps from SolrZkClientTest.testWrappingWatches (#1936)
    
    Only sleep when tests are nightly
---
 .../apache/solr/common/cloud/SolrZkClientTest.java    | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java b/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java
index 50bac49..01d412e 100644
--- a/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java
@@ -24,6 +24,8 @@ import java.security.NoSuchAlgorithmException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.solr.client.solrj.impl.CloudSolrClient;
@@ -150,16 +152,20 @@ public class SolrZkClientTest extends SolrCloudTestCase {
   // SOLR-13491
   public void testWrappingWatches() throws Exception {
     AtomicInteger calls = new AtomicInteger(0);
+    Semaphore semA = new Semaphore(0);
+    Semaphore semB = new Semaphore(0);
     Watcher watcherA = new Watcher() {
       @Override
       public void process(WatchedEvent event) {
         calls.getAndIncrement();
+        semA.release();
       }
     };
     Watcher watcherB = new Watcher() {
       @Override
       public void process(WatchedEvent event) {
         calls.getAndDecrement();
+        semB.release();
       }
     };
     Watcher wrapped1A = defaultClient.wrapWatcher(watcherA);
@@ -185,7 +191,11 @@ public class SolrZkClientTest extends SolrCloudTestCase {
     CollectionAdminRequest.setCollectionProperty(getSaferTestName(),"baz", "bam")
         .process(solrClient);
 
-    Thread.sleep(1000); // make sure zk client watch has time to be notified.
+    assertTrue("Watch A didn't trigger", semA.tryAcquire(5, TimeUnit.SECONDS));
+    if (TEST_NIGHTLY) {
+      // give more time in nightly tests to ensure no extra watch calls
+      Thread.sleep(500);
+    }
     assertEquals(1, calls.get()); // same wrapped watch set twice, only invoked once
 
     solrClient.getZkStateReader().getZkClient().getData("/collections/" + getSaferTestName() + "/collectionprops.json",wrapped1A, null,true);
@@ -194,7 +204,12 @@ public class SolrZkClientTest extends SolrCloudTestCase {
     CollectionAdminRequest.setCollectionProperty(getSaferTestName(),"baz", "bang")
         .process(solrClient);
 
-    Thread.sleep(1000); // make sure zk client watch has time to be notified.
+    assertTrue("Watch A didn't trigger", semA.tryAcquire(5, TimeUnit.SECONDS));
+    assertTrue("Watch B didn't trigger", semB.tryAcquire(5, TimeUnit.SECONDS));
+    if (TEST_NIGHTLY) {
+      // give more time in nightly tests to ensure no extra watch calls
+      Thread.sleep(500);
+    }
     assertEquals(1, calls.get()); // offsetting watches, no change
   }