Update test to cope with asynchronous writing of the access log
Previously, the test that verified that Undertow's access log could be enabled and was written to the correct file expected the log to be available as soon as the request to the server had completed. Undertow writes the access log asynchronously so the test failed intermittently due to a race between the access log being written and the test asserting that it exists. This commit updates the test to wait for up to 10 seconds for the access log to be available. See gh-4670
This commit is contained in:
parent
74ea3b9c9c
commit
03d29fd68d
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue