Skip to content

Commit 9ce7a5a

Browse files
authored
Clean up Node Shutdown metadata in test cleanup (#72726)
This commit ensures that node shutdown metadata is cleaned up between tests, as it causes unrelated tests to fail if a test leaves node shutdown metadata in place.
1 parent 47719f8 commit 9ce7a5a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,34 @@ private void wipeCluster() throws Exception {
705705
deleteAllAutoFollowPatterns();
706706
}
707707

708+
deleteAllNodeShutdownMetadata();
709+
708710
assertThat("Found in progress snapshots [" + inProgressSnapshots.get() + "].", inProgressSnapshots.get(), anEmptyMap());
709711
}
710712

713+
/**
714+
* If any nodes are registered for shutdown, removes their metadata.
715+
*/
716+
@SuppressWarnings("unchecked")
717+
private static void deleteAllNodeShutdownMetadata() throws IOException {
718+
final boolean NODE_SHUTDOWN_ENABLED = "true".equals(System.getProperty("es.shutdown_feature_flag_enabled"));
719+
if (NODE_SHUTDOWN_ENABLED == false) {
720+
return;
721+
}
722+
Request getShutdownStatus = new Request("GET", "_nodes/shutdown");
723+
Map<String, Object> statusResponse = responseAsMap(client().performRequest(getShutdownStatus));
724+
if (statusResponse.get("nodes") instanceof List) { // for some reason `nodes` is parsed as a Map<> if it's empty
725+
List<Map<String, Object>> nodesArray = (List<Map<String, Object>>) statusResponse.get("nodes");
726+
List<String> nodeIds = nodesArray.stream()
727+
.map(nodeShutdownMetadata -> (String) nodeShutdownMetadata.get("node_id"))
728+
.collect(Collectors.toUnmodifiableList());
729+
for (String nodeId : nodeIds) {
730+
Request deleteRequest = new Request("DELETE", "_nodes/" + nodeId + "/shutdown");
731+
assertOK(client().performRequest(deleteRequest));
732+
}
733+
}
734+
}
735+
711736
protected static void wipeAllIndices() throws IOException {
712737
boolean includeHidden = minimumNodeVersion().onOrAfter(Version.V_7_7_0);
713738
try {

x-pack/plugin/shutdown/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/shutdown/NodeShutdownIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public void testCRUD() throws Exception {
6565
/**
6666
* A very basic smoke test to make sure the allocation decider is working.
6767
*/
68-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/72589")
6968
@SuppressWarnings("unchecked")
7069
public void testAllocationPreventedForRemoval() throws Exception {
7170
Request nodesRequest = new Request("GET", "_nodes");

0 commit comments

Comments
 (0)