From 671438bc443a71d1681f31c715ecbe29692d247b Mon Sep 17 00:00:00 2001 From: Andrey Pleskach Date: Fri, 14 Jun 2024 15:57:42 +0200 Subject: [PATCH] Fixes flaky integration tests (#4452) Signed-off-by: Andrey Pleskach --- .../security/AbstractDefaultConfigurationTests.java | 10 ---------- .../DefaultConfigurationMultiNodeClusterTests.java | 11 +++++++++++ ...igurationMultiNodeClusterUseClusterStateTests.java | 11 +++++++++++ .../DefaultConfigurationSingleNodeClusterTests.java | 11 +++++++++++ ...gurationSingleNodeClusterUseClusterStateTests.java | 11 +++++++++++ 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/integrationTest/java/org/opensearch/security/AbstractDefaultConfigurationTests.java b/src/integrationTest/java/org/opensearch/security/AbstractDefaultConfigurationTests.java index 5387b3e516..cbb8a911ba 100644 --- a/src/integrationTest/java/org/opensearch/security/AbstractDefaultConfigurationTests.java +++ b/src/integrationTest/java/org/opensearch/security/AbstractDefaultConfigurationTests.java @@ -9,8 +9,6 @@ */ package org.opensearch.security; -import java.io.IOException; -import java.nio.file.Path; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -18,10 +16,8 @@ import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; import com.fasterxml.jackson.databind.JsonNode; -import org.apache.commons.io.FileUtils; import org.apache.http.HttpStatus; import org.awaitility.Awaitility; -import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,7 +38,6 @@ @RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class) @ThreadLeakScope(ThreadLeakScope.Scope.NONE) public abstract class AbstractDefaultConfigurationTests { - public final static Path configurationFolder = ConfigurationFiles.createConfigurationDirectory(); private static final TestSecurityConfig.User ADMIN_USER = new TestSecurityConfig.User("admin"); private static final TestSecurityConfig.User NEW_USER = new TestSecurityConfig.User("new-user"); private static final TestSecurityConfig.User LIMITED_USER = new TestSecurityConfig.User("limited-user"); @@ -53,11 +48,6 @@ protected AbstractDefaultConfigurationTests(LocalCluster cluster) { this.cluster = cluster; } - @AfterClass - public static void cleanConfigurationDirectory() throws IOException { - FileUtils.deleteDirectory(configurationFolder.toFile()); - } - @Test public void shouldLoadDefaultConfiguration() { try (TestRestClient client = cluster.getRestClient(NEW_USER)) { diff --git a/src/integrationTest/java/org/opensearch/security/DefaultConfigurationMultiNodeClusterTests.java b/src/integrationTest/java/org/opensearch/security/DefaultConfigurationMultiNodeClusterTests.java index 704e2c7255..18f6e61098 100644 --- a/src/integrationTest/java/org/opensearch/security/DefaultConfigurationMultiNodeClusterTests.java +++ b/src/integrationTest/java/org/opensearch/security/DefaultConfigurationMultiNodeClusterTests.java @@ -9,9 +9,13 @@ */ package org.opensearch.security; +import java.io.IOException; +import java.nio.file.Path; import java.util.List; import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.AfterClass; import org.junit.ClassRule; import org.opensearch.test.framework.cluster.ClusterManager; @@ -19,6 +23,8 @@ public class DefaultConfigurationMultiNodeClusterTests extends AbstractDefaultConfigurationTests { + static Path configurationFolder = ConfigurationFiles.createConfigurationDirectory(); + @ClassRule public static LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.THREE_CLUSTER_MANAGERS) .nodeSettings( @@ -33,6 +39,11 @@ public class DefaultConfigurationMultiNodeClusterTests extends AbstractDefaultCo .loadConfigurationIntoIndex(false) .build(); + @AfterClass + public static void cleanConfigurationDirectory() throws IOException { + FileUtils.deleteDirectory(configurationFolder.toFile()); + } + public DefaultConfigurationMultiNodeClusterTests() { super(cluster); } diff --git a/src/integrationTest/java/org/opensearch/security/DefaultConfigurationMultiNodeClusterUseClusterStateTests.java b/src/integrationTest/java/org/opensearch/security/DefaultConfigurationMultiNodeClusterUseClusterStateTests.java index 8abffac9cf..8bb1d5fede 100644 --- a/src/integrationTest/java/org/opensearch/security/DefaultConfigurationMultiNodeClusterUseClusterStateTests.java +++ b/src/integrationTest/java/org/opensearch/security/DefaultConfigurationMultiNodeClusterUseClusterStateTests.java @@ -9,9 +9,13 @@ */ package org.opensearch.security; +import java.io.IOException; +import java.nio.file.Path; import java.util.List; import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.AfterClass; import org.junit.ClassRule; import org.opensearch.test.framework.cluster.ClusterManager; @@ -19,6 +23,8 @@ public class DefaultConfigurationMultiNodeClusterUseClusterStateTests extends AbstractDefaultConfigurationTests { + static Path configurationFolder = ConfigurationFiles.createConfigurationDirectory(); + @ClassRule public static LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.THREE_CLUSTER_MANAGERS) .nodeSettings( @@ -35,6 +41,11 @@ public class DefaultConfigurationMultiNodeClusterUseClusterStateTests extends Ab .loadConfigurationIntoIndex(false) .build(); + @AfterClass + public static void cleanConfigurationDirectory() throws IOException { + FileUtils.deleteDirectory(configurationFolder.toFile()); + } + public DefaultConfigurationMultiNodeClusterUseClusterStateTests() { super(cluster); } diff --git a/src/integrationTest/java/org/opensearch/security/DefaultConfigurationSingleNodeClusterTests.java b/src/integrationTest/java/org/opensearch/security/DefaultConfigurationSingleNodeClusterTests.java index 362245db5e..9b546c258d 100644 --- a/src/integrationTest/java/org/opensearch/security/DefaultConfigurationSingleNodeClusterTests.java +++ b/src/integrationTest/java/org/opensearch/security/DefaultConfigurationSingleNodeClusterTests.java @@ -9,10 +9,14 @@ */ package org.opensearch.security; +import java.io.IOException; +import java.nio.file.Path; import java.util.List; import java.util.Map; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; +import org.apache.commons.io.FileUtils; +import org.junit.AfterClass; import org.junit.ClassRule; import org.junit.runner.RunWith; @@ -23,6 +27,8 @@ @ThreadLeakScope(ThreadLeakScope.Scope.NONE) public class DefaultConfigurationSingleNodeClusterTests extends AbstractDefaultConfigurationTests { + static Path configurationFolder = ConfigurationFiles.createConfigurationDirectory(); + @ClassRule public static LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.SINGLENODE) .nodeSettings( @@ -37,6 +43,11 @@ public class DefaultConfigurationSingleNodeClusterTests extends AbstractDefaultC .loadConfigurationIntoIndex(false) .build(); + @AfterClass + public static void cleanConfigurationDirectory() throws IOException { + FileUtils.deleteDirectory(configurationFolder.toFile()); + } + public DefaultConfigurationSingleNodeClusterTests() { super(cluster); } diff --git a/src/integrationTest/java/org/opensearch/security/DefaultConfigurationSingleNodeClusterUseClusterStateTests.java b/src/integrationTest/java/org/opensearch/security/DefaultConfigurationSingleNodeClusterUseClusterStateTests.java index e05005e912..d70a4f74b2 100644 --- a/src/integrationTest/java/org/opensearch/security/DefaultConfigurationSingleNodeClusterUseClusterStateTests.java +++ b/src/integrationTest/java/org/opensearch/security/DefaultConfigurationSingleNodeClusterUseClusterStateTests.java @@ -9,9 +9,13 @@ */ package org.opensearch.security; +import java.io.IOException; +import java.nio.file.Path; import java.util.List; import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.AfterClass; import org.junit.ClassRule; import org.opensearch.test.framework.cluster.ClusterManager; @@ -19,6 +23,8 @@ public class DefaultConfigurationSingleNodeClusterUseClusterStateTests extends AbstractDefaultConfigurationTests { + static Path configurationFolder = ConfigurationFiles.createConfigurationDirectory(); + @ClassRule public static LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.SINGLENODE) .nodeSettings( @@ -35,6 +41,11 @@ public class DefaultConfigurationSingleNodeClusterUseClusterStateTests extends A .loadConfigurationIntoIndex(false) .build(); + @AfterClass + public static void cleanConfigurationDirectory() throws IOException { + FileUtils.deleteDirectory(configurationFolder.toFile()); + } + public DefaultConfigurationSingleNodeClusterUseClusterStateTests() { super(cluster); }