Skip to content

Commit fe72f3a

Browse files
committed
fixed undeterministic RollingAppenderDirectCronTest
1 parent 745d096 commit fe72f3a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectCronTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public RolloverDelay(final RollingFileManager manager) {
7878
}
7979

8080
public void waitForRollover() {
81-
waitAtMost(5, TimeUnit.SECONDS)
81+
waitAtMost(7, TimeUnit.SECONDS)
8282
.alias("Rollover timeout")
8383
.until(() -> latch.getCount() == 0 || assertion != null);
8484
if (assertion != null) {
@@ -102,16 +102,18 @@ public void rolloverComplete(final String fileName) {
102102
final Path path = Paths.get(fileName);
103103
final Matcher matcher = FILE_PATTERN.matcher(path.getFileName().toString());
104104
assertThat(matcher).as("Rolled file").matches();
105-
try {
106-
final List<String> lines = Files.readAllLines(path);
107-
assertThat(lines).isNotEmpty();
108-
assertThat(lines.get(0)).startsWith(matcher.group(1));
109-
} catch (final IOException ex) {
110-
fail("Unable to read file " + fileName + ": " + ex.getMessage());
111-
}
105+
106+
// Wait until the file is non-empty (or timeout)
107+
waitAtMost(2, TimeUnit.SECONDS).until(() -> Files.exists(path) && Files.size(path) > 0);
108+
109+
final List<String> lines = Files.readAllLines(path);
110+
assertThat(lines).isNotEmpty();
111+
assertThat(lines.get(0)).startsWith(matcher.group(1));
112112
latch.countDown();
113113
} catch (final AssertionError ex) {
114114
assertion = ex;
115+
} catch (final IOException ex) {
116+
fail("Unable to read file " + fileName + ": " + ex.getMessage());
115117
}
116118
}
117119
}

0 commit comments

Comments
 (0)