Skip to content

Commit 3c3d380

Browse files
authored
Fix race condition in SearchOnlyReplicaIT (#18072)
I observed a failure in local testing due to this issue. The code previously was assuming it would observe a yellow cluster after restarting a node, but the node could restart and re-join the cluster before the assertion causing a failure. The `onNodeStopped` callback lets the test execute code before the node is restarted, so it should fix this issue. Signed-off-by: Andrew Ross <andrross@amazon.com>
1 parent ee6ca34 commit 3c3d380

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

server/src/internalClusterTest/java/org/opensearch/indices/settings/SearchOnlyReplicaIT.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,15 @@ public void testFailoverWithSearchReplicaWhenSearchNodeRestarts() throws Excepti
152152
String searchNode = internalCluster().startSearchOnlyNode();
153153
ensureGreen(TEST_INDEX);
154154
// Restart Search Node
155-
internalCluster().restartNode(searchNode);
156-
// Ensure search shard is unassigned
157-
ensureYellowAndNoInitializingShards(TEST_INDEX);
158-
assertActiveSearchShards(0);
155+
internalCluster().restartNode(searchNode, new InternalTestCluster.RestartCallback() {
156+
@Override
157+
public Settings onNodeStopped(String nodeName) throws Exception {
158+
// Ensure search shard is unassigned
159+
ensureYellowAndNoInitializingShards(TEST_INDEX);
160+
assertActiveSearchShards(0);
161+
return super.onNodeStopped(nodeName);
162+
}
163+
});
159164
// Ensure search shard is recovered
160165
ensureGreen(TEST_INDEX);
161166
assertActiveSearchShards(1);

0 commit comments

Comments
 (0)