Commit 504de8a7 authored by Andy Wilkinson's avatar Andy Wilkinson

Flush OutputStream-based appenders in Log4J 2 Tests

CI has been failing intermittently with failures in
Log4J2LoggingSystemTests. A possible cause of the failures is that
log entries are being buffered in an output stream. This may cause
an expected log entry to be absent (the entry is buffered) or an
unexpected entry to be present (the previously buffered entry has
now been flushed).

This commit attempts to address the test failures by ensuring that
all OutputStream-based appenders are flushed at the end of every test.

Closes gh-1864
parent 92595643
...@@ -17,9 +17,13 @@ ...@@ -17,9 +17,13 @@
package org.springframework.boot.logging.log4j2; package org.springframework.boot.logging.log4j2;
import java.io.File; import java.io.File;
import java.util.Map.Entry;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
...@@ -55,6 +59,17 @@ public class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests { ...@@ -55,6 +59,17 @@ public class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
this.logger = LogManager.getLogger(getClass()); this.logger = LogManager.getLogger(getClass());
} }
@After
public void flushAllOutputStreamAppenders() {
for (Entry<String, Appender> entry : ((org.apache.logging.log4j.core.Logger) this.logger)
.getAppenders().entrySet()) {
Appender appender = entry.getValue();
if (appender instanceof AbstractOutputStreamAppender) {
((AbstractOutputStreamAppender<?>) appender).getManager().flush();
}
}
}
@Test @Test
public void noFile() throws Exception { public void noFile() throws Exception {
this.loggingSystem.beforeInitialize(); this.loggingSystem.beforeInitialize();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment