Apache Lucene open-source search software
SOLR-9486: Fix race in AutoCommitTest
Alan Woodward6687244667a5
diff --git a/solr/core/src/test/org/apache/solr/update/AutoCommitTest.java b/solr/core/src/test/org/apache/solr/update/AutoCommitTest.javaindex 3221693e547..f68e56309a6 100644--- a/solr/core/src/test/org/apache/solr/update/AutoCommitTest.java+++ b/solr/core/src/test/org/apache/solr/update/AutoCommitTest.java@@ -20,6 +20,7 @@ import java.lang.invoke.MethodHandles;import java.util.ArrayList;import java.util.Collection;import java.util.HashMap;+import java.util.concurrent.CountDownLatch;import java.util.concurrent.TimeUnit;import org.apache.lucene.util.LuceneTestCase.Slow;@@ -49,6 +50,8 @@ class NewSearcherListener implements SolrEventListener {private volatile TriggerOn triggerOnType;private volatile SolrIndexSearcher newSearcher;+ private CountDownLatch latch;+public NewSearcherListener() {this(TriggerOn.Both);}@@ -63,6 +66,7 @@ class NewSearcherListener implements SolrEventListener {@Overridepublic void newSearcher(SolrIndexSearcher newSearcher,SolrIndexSearcher currentSearcher) {+ waitForTrigger();if (triggerOnType == TriggerOn.Soft && lastType == TriggerOn.Soft) {triggered = true;} else if (triggerOnType == TriggerOn.Hard && lastType == TriggerOn.Hard) {@@ -84,6 +88,29 @@ class NewSearcherListener implements SolrEventListener {lastType = TriggerOn.Soft;}+ private void waitForTrigger() {+ if (latch != null) {+ try {+ if (latch.await(30, TimeUnit.SECONDS) == false) {+ throw new AssertionError("Timed out waiting for search trigger to be released");+ }+ } catch (InterruptedException e) {+ throw new AssertionError("Interrupted waiting for new searcher");+ }+ }+ }++ public void pause() {+ latch = new CountDownLatch(1);+ }++ public void unpause() {+ if (latch != null) {+ latch.countDown();+ latch = null;+ }+ }+public void reset() {triggered = false;// log.info("TEST: trigger reset");@@ -316,6 +343,7 @@ public class AutoCommitTest extends AbstractSolrTestCase {assertQ("shouldn't find any", req("id:530") ,"//result[@numFound=0]" );// Delete one document with commitWithin+ trigger.pause();req.setContentStreams( toContentStreams(delI("529", "commitWithin", "2000"), null ) );trigger.reset();@@ -323,6 +351,7 @@ public class AutoCommitTest extends AbstractSolrTestCase {// Now make sure we can find itassertQ("should find one", req("id:529") ,"//result[@numFound=1]" );+ trigger.unpause();// Wait for the commit to happenassertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));diff --git a/solr/core/src/test/org/apache/solr/update/HardAutoCommitTest.java b/solr/core/src/test/org/apache/solr/update/HardAutoCommitTest.javaindex eb2e8aac9d1..3c652b256b7 100644--- a/solr/core/src/test/org/apache/solr/update/HardAutoCommitTest.java+++ b/solr/core/src/test/org/apache/solr/update/HardAutoCommitTest.java@@ -90,6 +90,7 @@ public class HardAutoCommitTest extends AbstractSolrTestCase {assertQ("shouldn't find any", req("id:530") ,"//result[@numFound=0]" );// Delete one document with commitWithin+ trigger.pause();req.setContentStreams( AutoCommitTest.toContentStreams(delI("529", "commitWithin", "1000"), null ) );trigger.reset();@@ -97,6 +98,7 @@ public class HardAutoCommitTest extends AbstractSolrTestCase {// Now make sure we can find itassertQ("should find one", req("id:529") ,"//result[@numFound=1]" );+ trigger.unpause();// Wait for the commit to happenassertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));