From ed20f2aa57a8494782e362decb48a3561936c194 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 10 Nov 2024 08:07:48 -0500 Subject: [PATCH 1/3] [IO-856] Try test on all OSs for GitHub CI --- src/test/java/org/apache/commons/io/FileUtilsListFilesTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/apache/commons/io/FileUtilsListFilesTest.java b/src/test/java/org/apache/commons/io/FileUtilsListFilesTest.java index 20e3c8d77a1..6def0148670 100644 --- a/src/test/java/org/apache/commons/io/FileUtilsListFilesTest.java +++ b/src/test/java/org/apache/commons/io/FileUtilsListFilesTest.java @@ -238,7 +238,7 @@ public void testListFilesWithDeletion() throws IOException { * Tests IO-856 ListFiles should not fail on vanishing files. */ @Test - @EnabledOnOs(value = OS.WINDOWS) + // @EnabledOnOs(value = OS.WINDOWS) public void testListFilesWithDeletionThreaded() throws ExecutionException, InterruptedException { // test for IO-856 // create random directory in tmp, create the directory if it does not exist From 399d6c0ee2c7dd78f788b28a4db0f255845f8291 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 8 Apr 2026 07:27:10 -0400 Subject: [PATCH 2/3] [IO-889] Tailer.close() does not guarantee file close - Add test class - Green on macOS locally --- .../commons/io/input/TailerCloseTest.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/test/java/org/apache/commons/io/input/TailerCloseTest.java diff --git a/src/test/java/org/apache/commons/io/input/TailerCloseTest.java b/src/test/java/org/apache/commons/io/input/TailerCloseTest.java new file mode 100644 index 00000000000..798a96291c9 --- /dev/null +++ b/src/test/java/org/apache/commons/io/input/TailerCloseTest.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.io.input; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +/** + * Tests {@link Tailer} for IO-889. + */ +public class TailerCloseTest { + + private class TailerTestListener extends TailerListenerAdapter { + + @Override + public void handle(final Exception ex) { + super.handle(ex); + result.completeExceptionally(ex); + } + + @Override + public void handle(final String line) { + super.handle(line); + result.complete(line); + } + } + + private static Thread newDaemonThread(final Runnable runnable) { + final Thread thread = new Thread(runnable, "commons-io-tailer"); + thread.setDaemon(true); + return thread; + } + + private ExecutorService executorService; + private Path path; + private final CompletableFuture result = new CompletableFuture<>(); + + @AfterEach + public void tearDown() throws Exception { + // wait for the tailer task and delete log file if previous delete failed + if (executorService != null) { + executorService.shutdown(); + executorService.awaitTermination(60, TimeUnit.SECONDS); + } + if (path != null && Files.exists(path)) { + Files.delete(path); + } + } + + @Test + public void testCloseTailer() throws Exception { + path = Files.createTempFile("TailerTestFile", ".log"); + // same as default Tailer executor + executorService = Executors.newSingleThreadExecutor(TailerCloseTest::newDaemonThread); + try ( + // @formatter:off + Tailer tailer = Tailer + .builder() + .setExecutorService(executorService) + .setTailerListener(new TailerTestListener()) + .setFile(path.toFile()) + .get()) { + // @formatter:on + Files.write(path, "aaa\n".getBytes()); + // wait for the background thread to open the file + assertEquals("aaa", result.get(60, TimeUnit.SECONDS)); + } + // delete file after closing Tailer + Files.delete(path); + } +} \ No newline at end of file From d9a19d707e80a8969d35137154752db9b0040aa0 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 8 Apr 2026 07:43:00 -0400 Subject: [PATCH 3/3] [IO-889] Tailer.close() does not guarantee file close - Add test class - Green on macOS locally - Fails on Windows on GH CI --- src/test/java/org/apache/commons/io/input/TailerCloseTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/org/apache/commons/io/input/TailerCloseTest.java b/src/test/java/org/apache/commons/io/input/TailerCloseTest.java index 798a96291c9..fbd94dd4af5 100644 --- a/src/test/java/org/apache/commons/io/input/TailerCloseTest.java +++ b/src/test/java/org/apache/commons/io/input/TailerCloseTest.java @@ -28,6 +28,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; /** * Tests {@link Tailer} for IO-889. @@ -71,6 +73,7 @@ public void tearDown() throws Exception { } } + @DisabledOnOs(value = OS.WINDOWS) @Test public void testCloseTailer() throws Exception { path = Files.createTempFile("TailerTestFile", ".log");