Skip to content

Commit

Permalink
Fix Flaky Test testPendingTasksWithClusterNotRecoveredBlock
Browse files Browse the repository at this point in the history
Signed-off-by: kkewwei <[email protected]>
Signed-off-by: kkewwei <[email protected]>

test
  • Loading branch information
kkewwei committed Feb 20, 2025
1 parent c34cedc commit ea2e674
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.action.admin.cluster.tasks;

import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest;
import org.opensearch.common.settings.Settings;
import org.opensearch.gateway.GatewayService;
import org.opensearch.test.InternalTestCluster;
Expand Down Expand Up @@ -91,11 +92,12 @@ public void testPendingTasksWithClusterNotRecoveredBlock() throws Exception {
}

// restart the cluster but prevent it from performing state recovery
final int nodeCount = client().admin().cluster().prepareNodesInfo("data:true", "cluster_manager:true").get().getNodes().size();
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
final int dataNodesCount = client().admin().cluster().prepareNodesInfo("data:true").get().getNodes().size();
internalCluster().fullRestart(new InternalTestCluster.RestartCallback() {
@Override
public Settings onNodeStopped(String nodeName) {
return Settings.builder().put(GatewayService.RECOVER_AFTER_DATA_NODES_SETTING.getKey(), nodeCount + 1).build();
return Settings.builder().put(GatewayService.RECOVER_AFTER_DATA_NODES_SETTING.getKey(), dataNodesCount + 1).build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public static boolean isReadOverrideException(Exception e) {
}

public static boolean isRetryableSearchException(final Exception e) {
return (OpenSearchException.status(e).getStatus() / 100 != 4) && (e.getCause() instanceof TaskCancelledException == false);

return (OpenSearchException.status(e).getStatus() / 100 != 4) && (e.getCause() instanceof TaskCancelledException == false)
// There exists a scenario where a primary shard (0 replicas) relocates and is in POST_RECOVERY on the
// target node but already deleted on the source node. Search request should still work.
|| (e.getCause() instanceof IndexNotFoundException);
}

}

0 comments on commit ea2e674

Please sign in to comment.