Skip to content

Commit d2c4d60

Browse files
committed
Fix Flaky Test SpecificClusterManagerNodesIT.testElectOnlyBetweenClusterManagerNodes
Signed-off-by: kkewwei <kewei.11@bytedance.com> Signed-off-by: kkewwei <kkewwei@163.com>
1 parent 5afb92f commit d2c4d60

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

server/src/internalClusterTest/java/org/opensearch/cluster/SpecificClusterManagerNodesIT.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.opensearch.test.OpenSearchIntegTestCase.Scope;
4545

4646
import java.io.IOException;
47+
import java.util.function.Supplier;
4748

4849
import static org.opensearch.test.NodeRoles.clusterManagerNode;
4950
import static org.opensearch.test.NodeRoles.dataOnlyNode;
@@ -254,9 +255,9 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception {
254255
logger.info("--> closing cluster-manager node (1)");
255256
client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(clusterManagerNodeName)).get();
256257
// removing the cluster-manager from the voting configuration immediately triggers the cluster-manager to step down
257-
assertBusy(() -> {
258-
assertThat(
259-
internalCluster().nonClusterManagerClient()
258+
Supplier<String> getClusterManagerIfElected = () -> {
259+
try {
260+
return internalCluster().nonClusterManagerClient()
260261
.admin()
261262
.cluster()
262263
.prepareState()
@@ -265,9 +266,14 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception {
265266
.getState()
266267
.nodes()
267268
.getClusterManagerNode()
268-
.getName(),
269-
equalTo(nextClusterManagerEligableNodeName)
270-
);
269+
.getName();
270+
} catch (Exception e) {
271+
logger.debug("failed to get cluster-manager name", e);
272+
return null;
273+
}
274+
};
275+
assertBusy(() -> {
276+
assertThat(getClusterManagerIfElected.get(), equalTo(nextClusterManagerEligableNodeName));
271277
assertThat(
272278
internalCluster().clusterManagerClient()
273279
.admin()

0 commit comments

Comments
 (0)