Skip to content

Apache Lucene open-source search software

SOLR-11576: CollectionsAPIDistributedZkTest.testCollectionsAPI() get failed when query node has stale clusterstate

Cao Manh Datf6cbce1c6ec4
diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
index b2f0d44a47a..b385b4f8f8b 100644
--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
@@ -457,7 +457,21 @@ public class CollectionsAPIDistributedZkTest extends SolrCloudTestCase {
.add("id", "7")
.add("id", "8")
.commit(cluster.getSolrClient(), collectionName);
- assertEquals(3, cluster.getSolrClient().query(collectionName, new SolrQuery("*:*")).getResults().getNumFound());
+ TimeOut timeOut = new TimeOut(10, TimeUnit.SECONDS);
+ while (!timeOut.hasTimedOut()) {
+ try {
+ long numFound = cluster.getSolrClient().query(collectionName, new SolrQuery("*:*")).getResults().getNumFound();
+ assertEquals(3, numFound);
+ break;
+ } catch (Exception e) {
+ // Query node can have stale clusterstate
+ log.info("Error when query " + collectionName, e);
+ Thread.sleep(500);
+ }
+ }
+ if (timeOut.hasTimedOut()) {
+ fail("Timeout on query " + collectionName);
+ }
checkNoTwoShardsUseTheSameIndexDir();
}