Commit 215689bd authored by Andy Wilkinson's avatar Andy Wilkinson

Use a local temp directory in logging system tests

Previously, the tests for Boot’s various logging systems used the
JVM’s default temp directory as the location of the spring.log file.
It is suspected that this was causing intermittent CI failures when
multiple Boot builds were running in parallel and tests were checking
for the presence of the spring.log file in the shared temp directory.

This commit updates AbstractLoggingSystemTests to configure a local
temp directory for the duration of the tests, thereby hopefully
eliminating failures caused by concurrent builds sharing the same
directory.

The previous attempt at fixing the intermittent CI failures (504de8a7)
has been removed as part of this commit as it did not fix the problem.

Closes gh-1864
parent f9221e24
...@@ -19,16 +19,36 @@ package org.springframework.boot.logging; ...@@ -19,16 +19,36 @@ package org.springframework.boot.logging;
import java.io.File; import java.io.File;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* Base for {@link LoggingSystem} tests. * Base for {@link LoggingSystem} tests.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Andy Wilkinson
*/ */
public abstract class AbstractLoggingSystemTests { public abstract class AbstractLoggingSystemTests {
private static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
private static String tempDir;
@BeforeClass
public static void configureTempdir() {
tempDir = System.getProperty(JAVA_IO_TMPDIR);
File newTempDir = new File("target/tmp");
newTempDir.mkdirs();
System.setProperty(JAVA_IO_TMPDIR, newTempDir.getAbsolutePath());
}
@AfterClass
public static void reinstateTempDir() {
System.setProperty(JAVA_IO_TMPDIR, tempDir);
}
@Before @Before
public void deleteTempLog() { public void deleteTempLog() {
new File(tmpDir() + "/spring.log").delete(); new File(tmpDir() + "/spring.log").delete();
...@@ -41,7 +61,7 @@ public abstract class AbstractLoggingSystemTests { ...@@ -41,7 +61,7 @@ public abstract class AbstractLoggingSystemTests {
} }
protected final String tmpDir() { protected final String tmpDir() {
String path = StringUtils.cleanPath(System.getProperty("java.io.tmpdir")); String path = StringUtils.cleanPath(System.getProperty(JAVA_IO_TMPDIR));
if (path.endsWith("/")) { if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1); path = path.substring(0, path.length() - 1);
} }
......
...@@ -17,13 +17,9 @@ ...@@ -17,13 +17,9 @@
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;
...@@ -59,17 +55,6 @@ public class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests { ...@@ -59,17 +55,6 @@ 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