-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Flaky Test SpecificClusterManagerNodesIT.testElectOnlyBetweenClusterManagerNodes #16021
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
import org.opensearch.test.OpenSearchIntegTestCase.Scope; | ||
|
||
import java.io.IOException; | ||
import java.util.function.Supplier; | ||
|
||
import static org.opensearch.test.NodeRoles.clusterManagerNode; | ||
import static org.opensearch.test.NodeRoles.dataOnlyNode; | ||
|
@@ -255,19 +256,24 @@ public void testElectOnlyBetweenClusterManagerNodes() throws Exception { | |
client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(clusterManagerNodeName)).get(); | ||
// removing the cluster-manager from the voting configuration immediately triggers the cluster-manager to step down | ||
assertBusy(() -> { | ||
assertThat( | ||
internalCluster().nonClusterManagerClient() | ||
.admin() | ||
.cluster() | ||
.prepareState() | ||
.execute() | ||
.actionGet() | ||
.getState() | ||
.nodes() | ||
.getClusterManagerNode() | ||
.getName(), | ||
equalTo(nextClusterManagerEligableNodeName) | ||
); | ||
Supplier<String> clusterManagerName = () -> { | ||
try { | ||
return internalCluster().nonClusterManagerClient() | ||
.admin() | ||
.cluster() | ||
.prepareState() | ||
.execute() | ||
.actionGet() | ||
.getState() | ||
.nodes() | ||
.getClusterManagerNode() | ||
.getName(); | ||
} catch (Exception e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of catching a generic exception, could we catch a specific exception related to ClusterManager Not found. |
||
logger.debug("failed to get cluster-manager name", e); | ||
return null; | ||
} | ||
}; | ||
assertThat(clusterManagerName.get(), equalTo(nextClusterManagerEligableNodeName)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if we swallow the NPE with the try/catch above, won't this test still fail on the assertion here since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jed326 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can add an additional assert before this to evaluate it is not null. |
||
assertThat( | ||
internalCluster().clusterManagerClient() | ||
.admin() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertBusy
block ?getClusterManagerIfElected