Skip to content

Commit

Permalink
Fix Flaky Test ClusterRerouteIT.testDelayWithALargeAmountOfShards (op…
Browse files Browse the repository at this point in the history
…ensearch-project#14510) (opensearch-project#14540)

Signed-off-by: kkewwei kkewwei@163.com

Signed-off-by: kkewwei kkewwei@163.com

(cherry picked from commit badf851)

Signed-off-by: kkewwei kkewwei@163.com
Signed-off-by: kkewwei <kkewwei@163.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Signed-off-by: kkewwei <kkewwei@163.com>
  • Loading branch information
2 people authored and kkewwei committed Jul 24, 2024
1 parent 94fd59b commit 922892a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ public void testDelayWithALargeAmountOfShards() throws Exception {
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(node_1));

// This might run slowly on older hardware
ensureGreen(TimeValue.timeValueMinutes(2));
// In some case, the shards will be rebalanced back and forth, it seems like a very low probability bug.
ensureGreen(TimeValue.timeValueMinutes(2), false);
}

private void rerouteWithAllocateLocalGateway(Settings commonSettings) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,10 @@ public ClusterHealthStatus ensureGreen(TimeValue timeout, String... indices) {
return ensureColor(ClusterHealthStatus.GREEN, timeout, false, indices);
}

public ClusterHealthStatus ensureGreen(TimeValue timeout, boolean waitForNoRelocatingShards, String... indices) {
return ensureColor(ClusterHealthStatus.GREEN, timeout, waitForNoRelocatingShards, false, indices);
}

/**
* Ensures the cluster has a yellow state via the cluster health API.
*/
Expand Down Expand Up @@ -890,6 +894,16 @@ private ClusterHealthStatus ensureColor(
TimeValue timeout,
boolean waitForNoInitializingShards,
String... indices
) {
return ensureColor(clusterHealthStatus, timeout, true, waitForNoInitializingShards, indices);
}

private ClusterHealthStatus ensureColor(
ClusterHealthStatus clusterHealthStatus,
TimeValue timeout,
boolean waitForNoRelocatingShards,
boolean waitForNoInitializingShards,
String... indices
) {
String color = clusterHealthStatus.name().toLowerCase(Locale.ROOT);
String method = "ensure" + Strings.capitalize(color);
Expand All @@ -898,7 +912,7 @@ private ClusterHealthStatus ensureColor(
.timeout(timeout)
.waitForStatus(clusterHealthStatus)
.waitForEvents(Priority.LANGUID)
.waitForNoRelocatingShards(true)
.waitForNoRelocatingShards(waitForNoRelocatingShards)
.waitForNoInitializingShards(waitForNoInitializingShards)
// We currently often use ensureGreen or ensureYellow to check whether the cluster is back in a good state after shutting down
// a node. If the node that is stopped is the cluster-manager node, another node will become cluster-manager and publish a
Expand Down

0 comments on commit 922892a

Please sign in to comment.