diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java index 9a1695c7452..477592259df 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java @@ -178,7 +178,8 @@ public class UndertowEmbeddedServletContainerFactoryTests } @Test - public void accessLogCanBeEnabled() throws IOException, URISyntaxException { + public void accessLogCanBeEnabled() + throws IOException, URISyntaxException, InterruptedException { UndertowEmbeddedServletContainerFactory factory = getFactory(); factory.setAccessLogEnabled(true); File accessLogDirectory = this.temporaryFolder.getRoot(); @@ -188,8 +189,9 @@ public class UndertowEmbeddedServletContainerFactoryTests new ServletRegistrationBean(new ExampleServlet(), "/hello")); this.container.start(); assertThat(getResponse(getLocalUrl("/hello")), equalTo("Hello World")); - assertThat(accessLogDirectory.listFiles(), - is(arrayContaining(new File(accessLogDirectory, "access_log.log")))); + File accessLog = new File(accessLogDirectory, "access_log.log"); + awaitFile(accessLog); + assertThat(accessLogDirectory.listFiles(), is(arrayContaining(accessLog))); } @Override @@ -197,6 +199,13 @@ public class UndertowEmbeddedServletContainerFactoryTests return null; // Undertow does not support JSPs } + private void awaitFile(File file) throws InterruptedException { + long end = System.currentTimeMillis() + 10000; + while (!file.exists() && System.currentTimeMillis() < end) { + Thread.sleep(100); + } + } + private ServletContainer getServletContainerFromNewFactory() { UndertowEmbeddedServletContainer undertow1 = (UndertowEmbeddedServletContainer) getFactory() .getEmbeddedServletContainer();