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

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


The following commit(s) were added to refs/heads/main by this push:
     new 5d8220c599f SOLR-18025 Test LeaderTragicEventTest flaky (#3939)
5d8220c599f is described below

commit 5d8220c599fa097d8a163c00899f9e5461dd7aae
Author: Jan Høydahl <[email protected]>
AuthorDate: Tue Dec 16 13:48:46 2025 +0100

    SOLR-18025 Test LeaderTragicEventTest flaky (#3939)
    
    Fix by implementing 3 retries
---
 .../apache/solr/cloud/LeaderTragicEventTest.java   | 52 +++++++++++++++++-----
 1 file changed, 41 insertions(+), 11 deletions(-)

diff --git 
a/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java 
b/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java
index c1520025fe8..01d84378474 100644
--- a/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java
@@ -26,7 +26,7 @@ import org.apache.lucene.store.AlreadyClosedException;
 import org.apache.solr.client.solrj.RemoteSolrException;
 import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.apache.HttpSolrClient;
+import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
 import org.apache.solr.client.solrj.request.CollectionAdminRequest;
 import org.apache.solr.client.solrj.request.QueryRequest;
 import org.apache.solr.client.solrj.request.SolrQuery;
@@ -113,7 +113,7 @@ public class LeaderTragicEventTest extends 
SolrCloudTestCase {
     updateResponse = new UpdateRequest().add("id", 
"2").commit(cluster.getSolrClient(), collection);
     assertEquals(0, updateResponse.getStatus());
     try (SolrClient followerClient =
-        new HttpSolrClient.Builder(oldLeader.getBaseUrl())
+        new HttpJettySolrClient.Builder(oldLeader.getBaseUrl())
             .withDefaultCollection(oldLeader.getCoreName())
             .build()) {
       QueryResponse queryResponse = new QueryRequest(new 
SolrQuery("*:*")).process(followerClient);
@@ -131,15 +131,45 @@ public class LeaderTragicEventTest extends 
SolrCloudTestCase {
       log.info("Will crash leader : {}", oldLeader);
 
       final Replica leaderReplica = dc.getLeader("shard1");
-      try (SolrClient solrClient = new 
HttpSolrClient.Builder(leaderReplica.getBaseUrl()).build()) {
-        new UpdateRequest().add("id", "99").commit(solrClient, 
leaderReplica.getCoreName());
-        fail("Should have injected tragedy");
-      } catch (RemoteSolrException e) {
-        // solrClient.add would throw RemoteSolrException with code 500
-        // or 404 if the bad replica has already been deleted
-        assertThat(e.code(), anyOf(is(500), is(404)));
-      } catch (AlreadyClosedException e) {
-        // If giving up leadership, might be already closed/closing
+
+      // Retry up to 3 times to ensure the tragic event is properly triggered
+      // This works around LUCENE-8692 where getTragicException() may not 
reflect all exceptions
+      int attempts = 0;
+      int maxAttempts = 3;
+      boolean tragedyTriggered = false;
+
+      while (attempts < maxAttempts && !tragedyTriggered) {
+        attempts++;
+        try (SolrClient solrClient =
+            new 
HttpJettySolrClient.Builder(leaderReplica.getBaseUrl()).build()) {
+          new UpdateRequest()
+              .add("id", "99_attempt_" + attempts)
+              .commit(solrClient, leaderReplica.getCoreName());
+        } catch (RemoteSolrException e) {
+          // solrClient.add would throw RemoteSolrException with code 500
+          // or 404 if the bad replica has already been deleted
+          assertThat(e.code(), anyOf(is(500), is(404)));
+          log.info("Tragic event triggered on attempt {}", attempts);
+          tragedyTriggered = true;
+        } catch (AlreadyClosedException e) {
+          // If giving up leadership, might be already closed/closing
+          log.info("Core already closed on attempt {} (leadership likely given 
up)", attempts);
+          tragedyTriggered = true;
+        }
+
+        // Brief pause between attempts to let the system stabilize
+        if (!tragedyTriggered && attempts < maxAttempts) {
+          try {
+            Thread.sleep(100);
+          } catch (InterruptedException ie) {
+            Thread.currentThread().interrupt();
+            throw new RuntimeException(ie);
+          }
+        }
+      }
+
+      if (!tragedyTriggered) {
+        fail("Failed to trigger tragic event after " + maxAttempts + " 
attempts");
       }
 
       return oldLeader;

Reply via email to