From 7075ed59875b68940549e1469a75bb27f54268bc Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Wed, 30 Mar 2022 19:55:50 +0000 Subject: [PATCH] Remove sleep when waiting for node closure For each node in the cluster we were removing and then sleeping for 250ms. There is an API that we can wait on to be sure the node has closed or at least take action if the closure wasn't successful. For the usage, which is cleaning up all nodes, switching to a best effort mode that could wait the same 250ms or return faster. Signed-off-by: Peter Nied --- .../security/test/helper/cluster/ClusterHelper.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/opensearch/security/test/helper/cluster/ClusterHelper.java b/src/test/java/org/opensearch/security/test/helper/cluster/ClusterHelper.java index 1ebd46cec6..75ad6e103b 100644 --- a/src/test/java/org/opensearch/security/test/helper/cluster/ClusterHelper.java +++ b/src/test/java/org/opensearch/security/test/helper/cluster/ClusterHelper.java @@ -39,6 +39,7 @@ import java.util.SortedSet; import java.util.TreeSet; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -247,10 +248,10 @@ public final void stopCluster() throws Exception { private void closeAllNodes() throws Exception { //close non master nodes - opensearchNodes.stream().filter(n->!n.isMasterEligible()).forEach(node->closeNode(node)); + opensearchNodes.stream().filter(n->!n.isMasterEligible()).forEach(ClusterHelper::closeNode); //close master nodes - opensearchNodes.stream().filter(n->n.isMasterEligible()).forEach(node->closeNode(node)); + opensearchNodes.stream().filter(n->n.isMasterEligible()).forEach(ClusterHelper::closeNode); opensearchNodes.clear(); clusterState = ClusterState.STOPPED; } @@ -258,7 +259,7 @@ private void closeAllNodes() throws Exception { private static void closeNode(Node node) { try { node.close(); - Thread.sleep(250); + node.awaitClose(250, TimeUnit.MILLISECONDS); } catch (Throwable e) { //ignore }