From 215689bd4dece56e7044034535edf090dda65914 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 11 Nov 2014 13:30:11 +0000 Subject: [PATCH] Use a local temp directory in logging system tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (504de8a) has been removed as part of this commit as it did not fix the problem. Closes gh-1864 --- .../logging/AbstractLoggingSystemTests.java | 22 ++++++++++++++++++- .../log4j2/Log4J2LoggingSystemTests.java | 15 ------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java index 81457f7c26..d370df9531 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java @@ -19,16 +19,36 @@ package org.springframework.boot.logging; import java.io.File; import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.springframework.util.StringUtils; /** * Base for {@link LoggingSystem} tests. * * @author Phillip Webb + * @author Andy Wilkinson */ 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 public void deleteTempLog() { new File(tmpDir() + "/spring.log").delete(); @@ -41,7 +61,7 @@ public abstract class AbstractLoggingSystemTests { } 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("/")) { path = path.substring(0, path.length() - 1); } diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java index c749b30d78..bf9305b1e9 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java @@ -17,13 +17,9 @@ package org.springframework.boot.logging.log4j2; import java.io.File; -import java.util.Map.Entry; import org.apache.logging.log4j.LogManager; 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.Ignore; import org.junit.Rule; @@ -59,17 +55,6 @@ public class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests { this.logger = LogManager.getLogger(getClass()); } - @After - public void flushAllOutputStreamAppenders() { - for (Entry entry : ((org.apache.logging.log4j.core.Logger) this.logger) - .getAppenders().entrySet()) { - Appender appender = entry.getValue(); - if (appender instanceof AbstractOutputStreamAppender) { - ((AbstractOutputStreamAppender) appender).getManager().flush(); - } - } - } - @Test public void noFile() throws Exception { this.loggingSystem.beforeInitialize();