Tweaking DisableUrlCacheTest to identify flaky nature of testcase. (#11670)

* Tweaking DisableUrlCacheTest to identify flaky nature of testcase.

* More logging details (in case failure happens)

* Repeat til failure
This commit is contained in:
Joakim Erdfelt 2024-04-23 20:31:32 -05:00 committed by GitHub
parent bb633b8a0f
commit 1f4d19c841
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 24 additions and 3 deletions

View File

@ -26,8 +26,10 @@ import org.eclipse.jetty.tests.distribution.AbstractJettyHomeTest;
import org.eclipse.jetty.tests.testers.JettyHomeTester;
import org.eclipse.jetty.tests.testers.Tester;
import org.eclipse.jetty.toolchain.test.FS;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.parallel.Isolated;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
@ -38,7 +40,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@Isolated
public class DisableUrlCacheTest extends AbstractJettyHomeTest
{
@Test
private static final Logger LOG = LoggerFactory.getLogger(DisableUrlCacheTest.class);
@RepeatedTest(value = 40, failureThreshold = 1)
public void testReloadWebAppWithLog4j2() throws Exception
{
Path jettyBase = newTestJettyBaseDirectory();
@ -65,6 +69,9 @@ public class DisableUrlCacheTest extends AbstractJettyHomeTest
Path tempDir = distribution.getJettyBase().resolve("work");
FS.ensureEmpty(tempDir);
Path resourcesDir = distribution.getJettyBase().resolve("resources");
FS.ensureEmpty(resourcesDir);
Path webappsDir = distribution.getJettyBase().resolve("webapps");
String warXml = """
<?xml version="1.0" encoding="ISO-8859-1"?>
@ -79,6 +86,17 @@ public class DisableUrlCacheTest extends AbstractJettyHomeTest
Path warXmlPath = webappsDir.resolve("test.xml");
Files.writeString(warXmlPath, warXml, StandardCharsets.UTF_8);
Path loggingFile = resourcesDir.resolve("jetty-logging.properties");
String loggingConfig = """
org.eclipse.jetty.LEVEL=INFO
org.eclipse.jetty.deploy.LEVEL=DEBUG
org.eclipse.jetty.ee10.webapp.LEVEL=DEBUG
org.eclipse.jetty.ee10.webapp.WebAppClassLoader.LEVEL=INFO
org.eclipse.jetty.ee10.servlet.LEVEL=DEBUG
""";
Files.writeString(loggingFile, loggingConfig, StandardCharsets.UTF_8);
int port = Tester.freePort();
String[] runArgs = {
"jetty.http.port=" + port,
@ -101,12 +119,14 @@ public class DisableUrlCacheTest extends AbstractJettyHomeTest
touch(warXmlPath);
// Wait for reload
// Started oeje10w.WebAppContext@3fec304{test,/test,b=file:///h
assertTrue(run2.awaitConsoleLogsFor("Started oeje10w.WebAppContext@", START_TIMEOUT, TimeUnit.SECONDS));
assertTrue(run2.awaitConsoleLogsFor("{test,/test,", START_TIMEOUT, TimeUnit.SECONDS));
// Is webapp still there?
response = client.GET("http://localhost:" + port + "/test/log/");
assertThat(response.getStatus(), is(HttpStatus.OK_200));
content = response.getContentAsString();
assertThat(content, response.getStatus(), is(HttpStatus.OK_200));
assertThat(content, containsString("GET at LogServlet"));
}
}
@ -114,6 +134,7 @@ public class DisableUrlCacheTest extends AbstractJettyHomeTest
private void touch(Path path) throws IOException
{
LOG.info("Touch: {}", path);
FileTime now = FileTime.fromMillis(System.currentTimeMillis() + 2000);
Files.setLastModifiedTime(path, now);
}