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

psalagnac pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new ec0913f056b Use latches instead of sleeping for one second in 
SplitShardTest. (#3954)
ec0913f056b is described below

commit ec0913f056b891f8a5dbb863e8fa295f82dec8f1
Author: Pierre Salagnac <[email protected]>
AuthorDate: Fri Dec 19 10:01:00 2025 +0100

    Use latches instead of sleeping for one second in SplitShardTest. (#3954)
---
 .../test/org/apache/solr/cloud/SplitShardTest.java | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java 
b/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java
index b8585de0c87..8f746ebed60 100644
--- a/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/SplitShardTest.java
@@ -23,11 +23,13 @@ import java.io.IOException;
 import java.lang.invoke.MethodHandles;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -262,10 +264,13 @@ public class SplitShardTest extends SolrCloudTestCase {
         new ConcurrentHashMap<>(); // what the index should contain
     final AtomicBoolean doIndex = new AtomicBoolean(true);
     final AtomicInteger docsIndexed = new AtomicInteger();
+    List<CountDownLatch> threadLatches = Collections.synchronizedList(new 
ArrayList<>());
     Thread[] indexThreads = new Thread[nThreads];
     try {
 
       for (int i = 0; i < nThreads; i++) {
+        int threadIndex = i;
+        threadLatches.add(new CountDownLatch(10));
         indexThreads[i] =
             new Thread(
                 () -> {
@@ -291,6 +296,7 @@ public class SplitShardTest extends SolrCloudTestCase {
                       fail(e.getMessage());
                       break;
                     }
+                    threadLatches.get(threadIndex).countDown();
                   }
                 });
       }
@@ -299,8 +305,12 @@ public class SplitShardTest extends SolrCloudTestCase {
         thread.start();
       }
 
-      Thread.sleep(100); // wait for a few docs to be indexed before invoking 
split
+      // wait for a few docs (10 requests per threads) to be indexed before 
invoking split
+      for (int i = 0; i < nThreads; i++) {
+        assertTrue(threadLatches.get(i).await(30, TimeUnit.SECONDS));
+      }
       int docCount = model.size();
+      assertTrue("no docs indexed", docCount > 0);
 
       CollectionAdminRequest.SplitShard splitShard =
           
CollectionAdminRequest.splitShard(collectionName).setShardName("shard1");
@@ -315,8 +325,14 @@ public class SplitShardTest extends SolrCloudTestCase {
       // make sure that docs were indexed during the split
       assertTrue(model.size() > docCount);
 
-      Thread.sleep(100); // wait for a few more docs to be indexed after split
-
+      // wait for a few more docs (10 more requests per thread) to be indexed 
after split
+      // Reset the latch of each thread, and them wait for all of them
+      for (int i = 0; i < nThreads; i++) {
+        threadLatches.set(i, new CountDownLatch(10));
+      }
+      for (int i = 0; i < nThreads; i++) {
+        assertTrue(threadLatches.get(i).await(30, TimeUnit.SECONDS));
+      }
     } finally {
       // shut down the indexers
       doIndex.set(false);

Reply via email to