From 8d0458baadbcf57ea438a6e7d08e5eede7cff8be Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Fri, 14 Feb 2025 16:41:28 +0100 Subject: [PATCH 1/3] Fix torture tests setup --- src/test/java/engineering/swat/watch/TortureTests.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/engineering/swat/watch/TortureTests.java b/src/test/java/engineering/swat/watch/TortureTests.java index 5704d864..20452708 100644 --- a/src/test/java/engineering/swat/watch/TortureTests.java +++ b/src/test/java/engineering/swat/watch/TortureTests.java @@ -50,7 +50,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.awaitility.Awaitility; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; @@ -64,6 +66,11 @@ class TortureTests { private TestDirectory testDir; + @BeforeAll + static void setupEverything() { + Awaitility.setDefaultTimeout(TestHelper.LONG_WAIT.getSeconds(), TimeUnit.SECONDS); + } + @BeforeEach void setup() throws IOException { testDir = new TestDirectory(); From d1385a4f4676e54aa8dd65f996917f42600aeae5 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Fri, 14 Feb 2025 16:42:57 +0100 Subject: [PATCH 2/3] Fix system property key to check which OS the tests are running on --- src/test/java/engineering/swat/watch/TestHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/engineering/swat/watch/TestHelper.java b/src/test/java/engineering/swat/watch/TestHelper.java index d30bfc77..6c2d3104 100644 --- a/src/test/java/engineering/swat/watch/TestHelper.java +++ b/src/test/java/engineering/swat/watch/TestHelper.java @@ -37,7 +37,7 @@ public class TestHelper { static { var delayFactorConfig = System.getenv("DELAY_FACTOR"); int delayFactor = delayFactorConfig == null ? 1 : Integer.parseInt(delayFactorConfig); - var os = System.getProperty("os", "?").toLowerCase(); + var os = System.getProperty("os.name", "?").toLowerCase(); if (os.contains("mac")) { // OSX is SLOW on it's watches delayFactor *= 2; From 23990d903649e04c6713cddcacd3d48d4690f629 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Fri, 14 Feb 2025 16:47:40 +0100 Subject: [PATCH 3/3] Fix warnings in tests --- .../java/engineering/swat/watch/APIErrorsTests.java | 2 +- .../java/engineering/swat/watch/DeleteLockTests.java | 3 +-- .../engineering/swat/watch/RecursiveWatchTests.java | 8 +++----- .../engineering/swat/watch/SingleDirectoryTests.java | 10 ++++------ .../java/engineering/swat/watch/SingleFileTests.java | 4 ++-- src/test/java/engineering/swat/watch/SmokeTests.java | 9 +++------ .../java/engineering/swat/watch/TortureTests.java | 12 +++--------- .../engineering/swat/watch/impl/BundlingTests.java | 8 +++----- 8 files changed, 20 insertions(+), 36 deletions(-) diff --git a/src/test/java/engineering/swat/watch/APIErrorsTests.java b/src/test/java/engineering/swat/watch/APIErrorsTests.java index ffa5b44c..67291671 100644 --- a/src/test/java/engineering/swat/watch/APIErrorsTests.java +++ b/src/test/java/engineering/swat/watch/APIErrorsTests.java @@ -37,7 +37,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class APIErrorsTests { +class APIErrorsTests { private TestDirectory testDir; diff --git a/src/test/java/engineering/swat/watch/DeleteLockTests.java b/src/test/java/engineering/swat/watch/DeleteLockTests.java index 1996515c..b3760745 100644 --- a/src/test/java/engineering/swat/watch/DeleteLockTests.java +++ b/src/test/java/engineering/swat/watch/DeleteLockTests.java @@ -51,7 +51,7 @@ void setup() throws IOException { } @AfterEach - void cleanup() throws IOException { + void cleanup() { if (testDir != null) { testDir.close(); } @@ -62,7 +62,6 @@ static void setupEverything() { Awaitility.setDefaultTimeout(TestHelper.NORMAL_WAIT); } - @FunctionalInterface private interface Deleter { void run(Path target) throws IOException; diff --git a/src/test/java/engineering/swat/watch/RecursiveWatchTests.java b/src/test/java/engineering/swat/watch/RecursiveWatchTests.java index 655a2b8d..5faa2122 100644 --- a/src/test/java/engineering/swat/watch/RecursiveWatchTests.java +++ b/src/test/java/engineering/swat/watch/RecursiveWatchTests.java @@ -31,7 +31,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -56,18 +55,17 @@ void setup() throws IOException { } @AfterEach - void cleanup() throws IOException { + void cleanup() { if (testDir != null) { testDir.close(); } } @BeforeAll - static void setupEverything() throws IOException { + static void setupEverything() { Awaitility.setDefaultTimeout(TestHelper.NORMAL_WAIT); } - @Test void newDirectoryWithFilesChangesDetected() throws IOException { var target = new AtomicReference(); @@ -123,7 +121,7 @@ void correctRelativePathIsReported() throws IOException { } @Test - void deleteOfFileInDirectoryShouldBeVisible() throws IOException, InterruptedException { + void deleteOfFileInDirectoryShouldBeVisible() throws IOException { var target = testDir.getTestFiles() .stream() .filter(p -> !p.getParent().equals(testDir.getTestDirectory())) diff --git a/src/test/java/engineering/swat/watch/SingleDirectoryTests.java b/src/test/java/engineering/swat/watch/SingleDirectoryTests.java index 63ec141b..72d0c656 100644 --- a/src/test/java/engineering/swat/watch/SingleDirectoryTests.java +++ b/src/test/java/engineering/swat/watch/SingleDirectoryTests.java @@ -30,8 +30,6 @@ import java.io.IOException; import java.nio.file.Files; -import java.time.Duration; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.awaitility.Awaitility; @@ -42,7 +40,7 @@ import engineering.swat.watch.WatchEvent.Kind; -public class SingleDirectoryTests { +class SingleDirectoryTests { private TestDirectory testDir; @BeforeEach @@ -51,7 +49,7 @@ void setup() throws IOException { } @AfterEach - void cleanup() throws IOException { + void cleanup() { if (testDir != null) { testDir.close(); } @@ -63,7 +61,7 @@ static void setupEverything() { } @Test - void deleteOfFileInDirectoryShouldBeVisible() throws IOException, InterruptedException { + void deleteOfFileInDirectoryShouldBeVisible() throws IOException { var target = testDir.getTestFiles().get(0); var seenDelete = new AtomicBoolean(false); var seenCreate = new AtomicBoolean(false); @@ -91,7 +89,7 @@ void deleteOfFileInDirectoryShouldBeVisible() throws IOException, InterruptedExc } @Test - void alternativeAPITest() throws IOException, InterruptedException { + void alternativeAPITest() throws IOException { var target = testDir.getTestFiles().get(0); var seenDelete = new AtomicBoolean(false); var seenCreate = new AtomicBoolean(false); diff --git a/src/test/java/engineering/swat/watch/SingleFileTests.java b/src/test/java/engineering/swat/watch/SingleFileTests.java index 71a2ab93..206bc9bf 100644 --- a/src/test/java/engineering/swat/watch/SingleFileTests.java +++ b/src/test/java/engineering/swat/watch/SingleFileTests.java @@ -40,7 +40,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class SingleFileTests { +class SingleFileTests { private TestDirectory testDir; @BeforeEach @@ -49,7 +49,7 @@ void setup() throws IOException { } @AfterEach - void cleanup() throws IOException { + void cleanup() { if (testDir != null) { testDir.close(); } diff --git a/src/test/java/engineering/swat/watch/SmokeTests.java b/src/test/java/engineering/swat/watch/SmokeTests.java index 29cfe506..592e64e0 100644 --- a/src/test/java/engineering/swat/watch/SmokeTests.java +++ b/src/test/java/engineering/swat/watch/SmokeTests.java @@ -32,7 +32,6 @@ import java.io.IOException; import java.nio.file.Files; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.awaitility.Awaitility; @@ -51,7 +50,7 @@ void setup() throws IOException { } @AfterEach - void cleanup() throws IOException { + void cleanup() { if (testDir != null) { testDir.close(); } @@ -63,7 +62,7 @@ static void setupEverything() { } @Test - void watchDirectory() throws IOException, InterruptedException { + void watchDirectory() throws IOException { var changed = new AtomicBoolean(false); var target = testDir.getTestFiles().get(0); var watchConfig = Watcher.watch(testDir.getTestDirectory(), WatchScope.PATH_AND_CHILDREN) @@ -77,7 +76,7 @@ void watchDirectory() throws IOException, InterruptedException { } @Test - void watchRecursiveDirectory() throws IOException, InterruptedException { + void watchRecursiveDirectory() throws IOException { var changed = new AtomicBoolean(false); var target = testDir.getTestFiles().stream() .filter(p -> !p.getParent().equals(testDir.getTestDirectory())) @@ -113,6 +112,4 @@ void watchSingleFile() throws IOException { await("Single file change").untilTrue(changed); } } - - } diff --git a/src/test/java/engineering/swat/watch/TortureTests.java b/src/test/java/engineering/swat/watch/TortureTests.java index 20452708..c2e49568 100644 --- a/src/test/java/engineering/swat/watch/TortureTests.java +++ b/src/test/java/engineering/swat/watch/TortureTests.java @@ -39,7 +39,6 @@ import java.util.Collections; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingDeque; @@ -58,8 +57,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; -import engineering.swat.watch.WatchEvent.Kind; - class TortureTests { private final Logger logger = LogManager.getLogger(); @@ -77,7 +74,7 @@ void setup() throws IOException { } @AfterEach - void cleanup() throws IOException { + void cleanup() { if (testDir != null) { testDir.close(); } @@ -97,7 +94,7 @@ private final class IOGenerator { } } - private final static int BURST_SIZE = 1000; + private static final int BURST_SIZE = 1000; private void startJob(final Path root, Random r, Executor exec) { exec.execute(() -> { @@ -246,7 +243,6 @@ void manyRegistrationsForSamePath() throws InterruptedException, IOException { done.acquire(TORTURE_REGISTRATION_THREADS - 1); assertTrue(seen.isEmpty(), "No events should have been sent"); var target = testDir.getTestDirectory().resolve("test124.txt"); - //logger.info("Writing: {}", target); Files.writeString(target, "Hello World"); var expected = Collections.singleton(target); await("We should see only one event") @@ -331,8 +327,6 @@ void manyRegisterAndUnregisterSameTime() throws InterruptedException, IOExceptio } - - @Test //Deletes can race the filesystem, so you might miss a few files in a dir, if that dir is already deleted @EnabledIfEnvironmentVariable(named="TORTURE_DELETE", matches="true") @@ -370,7 +364,7 @@ void pressureOnFSShouldNotMissDeletes() throws InterruptedException, IOException }); try (var activeWatch = watchConfig.start() ) { - logger.info("Deleting files now", THREADS); + logger.info("Deleting files now ({} threads)", THREADS); testDir.deleteAllFiles(); logger.info("Waiting for the events processing to stabilize"); waitForStable(events, happened); diff --git a/src/test/java/engineering/swat/watch/impl/BundlingTests.java b/src/test/java/engineering/swat/watch/impl/BundlingTests.java index f5c406e4..a6aff001 100644 --- a/src/test/java/engineering/swat/watch/impl/BundlingTests.java +++ b/src/test/java/engineering/swat/watch/impl/BundlingTests.java @@ -54,7 +54,7 @@ import engineering.swat.watch.impl.util.BundledSubscription; import engineering.swat.watch.impl.util.ISubscribable; -public class BundlingTests { +class BundlingTests { private final Logger logger = LogManager.getLogger(); private BundledSubscription target; @@ -77,8 +77,7 @@ void publish(Long x) { s.accept(true); } } - }; - + } @BeforeEach void setup() { @@ -134,7 +133,7 @@ void manySubscriptions() throws IOException { } @RepeatedTest(failureThreshold = 1, value=50) - void parallelSubscriptions() throws IOException, InterruptedException { + void parallelSubscriptions() throws InterruptedException { var hits = new AtomicInteger(); var endPointReached = new Semaphore(0); var waitingForClose = new Semaphore(0); @@ -171,5 +170,4 @@ void parallelSubscriptions() throws IOException, InterruptedException { .untilAtomic(hits, IsEqual.equalTo(active)); waitingForClose.release(active); } - }