From 3de64e8ccdc9a0acfb1caf757c398dd9669b6d84 Mon Sep 17 00:00:00 2001 From: rjuare8 Date: Thu, 2 Oct 2025 23:30:28 -0500 Subject: [PATCH] fixed undeterministic RollingAppenderDirectCronTest --- .../rolling/RollingAppenderDirectCronTest.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectCronTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectCronTest.java index 6751d3cb1f6..cfadd237577 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectCronTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectCronTest.java @@ -78,7 +78,7 @@ public RolloverDelay(final RollingFileManager manager) { } public void waitForRollover() { - waitAtMost(5, TimeUnit.SECONDS) + waitAtMost(7, TimeUnit.SECONDS) .alias("Rollover timeout") .until(() -> latch.getCount() == 0 || assertion != null); if (assertion != null) { @@ -102,16 +102,18 @@ public void rolloverComplete(final String fileName) { final Path path = Paths.get(fileName); final Matcher matcher = FILE_PATTERN.matcher(path.getFileName().toString()); assertThat(matcher).as("Rolled file").matches(); - try { - final List lines = Files.readAllLines(path); - assertThat(lines).isNotEmpty(); - assertThat(lines.get(0)).startsWith(matcher.group(1)); - } catch (final IOException ex) { - fail("Unable to read file " + fileName + ": " + ex.getMessage()); - } + + // Wait until the file is non-empty (or timeout) + waitAtMost(2, TimeUnit.SECONDS).until(() -> Files.exists(path) && Files.size(path) > 0); + + final List lines = Files.readAllLines(path); + assertThat(lines).isNotEmpty(); + assertThat(lines.get(0)).startsWith(matcher.group(1)); latch.countDown(); } catch (final AssertionError ex) { assertion = ex; + } catch (final IOException ex) { + fail("Unable to read file " + fileName + ": " + ex.getMessage()); } } }