@@ -852,8 +852,7 @@ protected boolean preserveSearchableSnapshotsIndicesUponCompletion() {
852852    }
853853
854854    private  void  wipeCluster () throws  Exception  {
855-         logger .info ("Waiting for all cluster updates up to this moment to be processed" );
856-         assertOK (adminClient ().performRequest (new  Request ("GET" , "_cluster/health?wait_for_events=languid" )));
855+         waitForClusterUpdates ();
857856
858857        // Cleanup rollup before deleting indices. A rollup job might have bulks in-flight, 
859858        // so we need to fully shut them down first otherwise a job might stall waiting 
@@ -991,6 +990,38 @@ private void wipeCluster() throws Exception {
991990        deleteAllNodeShutdownMetadata ();
992991    }
993992
993+     private  void  waitForClusterUpdates () throws  Exception  {
994+         logger .info ("Waiting for all cluster updates up to this moment to be processed" );
995+         try  {
996+             assertOK (adminClient ().performRequest (new  Request ("GET" , "_cluster/health?wait_for_events=languid" )));
997+         } catch  (ResponseException  e ) {
998+             if  (e .getResponse ().getStatusLine ().getStatusCode () == HttpStatus .SC_REQUEST_TIMEOUT ) {
999+                 final  var  pendingTasks  = getPendingClusterStateTasks ();
1000+                 if  (pendingTasks  != null ) {
1001+                     logger .error ("Timed out waiting for cluster updates to be processed, {}" , pendingTasks );
1002+                 }
1003+             }
1004+             throw  e ;
1005+         }
1006+     }
1007+ 
1008+     private  static  String  getPendingClusterStateTasks () {
1009+         try  {
1010+             Response  response  = adminClient ().performRequest (new  Request ("GET" , "/_cluster/pending_tasks" ));
1011+             List <?> tasks  = (List <?>) entityAsMap (response ).get ("tasks" );
1012+             if  (false  == tasks .isEmpty ()) {
1013+                 StringBuilder  message  = new  StringBuilder ("there are still running tasks:" );
1014+                 for  (Object  task  : tasks ) {
1015+                     message .append ('\n' ).append (task .toString ());
1016+                 }
1017+                 return  message .toString ();
1018+             }
1019+         } catch  (IOException  e ) {
1020+             fail (e , "Failed to retrieve pending tasks in the cluster during cleanup" );
1021+         }
1022+         return  null ;
1023+     }
1024+ 
9941025    /** 
9951026     * This method checks whether ILM policies or templates get recreated after they have been deleted. If so, we are probably deleting 
9961027     * them unnecessarily, potentially causing test performance problems. This could happen for example if someone adds a new standard ILM 
@@ -1461,18 +1492,9 @@ private void logIfThereAreRunningTasks() throws IOException {
14611492     */ 
14621493    private  static  void  waitForClusterStateUpdatesToFinish () throws  Exception  {
14631494        assertBusy (() -> {
1464-             try  {
1465-                 Response  response  = adminClient ().performRequest (new  Request ("GET" , "/_cluster/pending_tasks" ));
1466-                 List <?> tasks  = (List <?>) entityAsMap (response ).get ("tasks" );
1467-                 if  (false  == tasks .isEmpty ()) {
1468-                     StringBuilder  message  = new  StringBuilder ("there are still running tasks:" );
1469-                     for  (Object  task  : tasks ) {
1470-                         message .append ('\n' ).append (task .toString ());
1471-                     }
1472-                     fail (message .toString ());
1473-                 }
1474-             } catch  (IOException  e ) {
1475-                 fail ("cannot get cluster's pending tasks: "  + e .getMessage ());
1495+             final  var  pendingTasks  = getPendingClusterStateTasks ();
1496+             if  (pendingTasks  != null ) {
1497+                 fail (pendingTasks );
14761498            }
14771499        }, 30 , TimeUnit .SECONDS );
14781500    }
0 commit comments