Skip to content

Commit

Permalink
Issue #5684 - Windows test overhaul (#6581)
Browse files Browse the repository at this point in the history
Issue #5684 - Window's test overhaul

+ Migrate from @DisabledOnOs(WINDOWS) to assumptions on capabilities instead.
+ Fix other outstanding windows testing issues.
+ Cleanup FileBufferedResponseHandlerTest expectations on Windows.
+ PathWatcher scan interval is variable on windows
+ If unable to start testcase based on assumption,
  the stop shouldn't fail testcase
+ Increase various wait timeouts
+ Make tests less strict due to system speed issues
+ Disable Sni tests due to TLS behaviors differences in Windows
  + Windows TLSv1.3 seems to introduce this difference
  + If we restrict to TLSv1.2 this passes.
  + On Linux TLSv.13 on client side will always return a
  + javax.net.ssl.SSLHandshakeException in those test cases that expect it.
  + However, on Windows, Only the TLSv1.2 implementation will return a javax.net.ssl.SSLHandshakeException,
  + All other TLS versions on Windows will result in a
  + javax.net.ssl.SSLException: Software caused connection abort: recv failed
+ Disable ConcurrentStreamCreationTest
  + Not possible to create all of these streams.
+ Fixing DeploymentTempDirTest
  + Using unique workdir per testcase.
  + Don't expect to delete files / directories between tests
    (not supported on windows due to file locking anyway)
 + Fixing line ending difference on windows
 + InvalidPathException is a 404 Not Found
 + Cannot reuse test directory between runs due to memory mapped files that are still in use from previous run.
 + java.nio.file.FileSystemException: C:\code\jetty.project\jetty-webapp\target\tests\welcome#\index.html: The requested operation cannot be performed on a file with a user-mapped section open.

	at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92)
	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
	at java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:235)
	at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:478)
	at java.base/java.nio.file.Files.newOutputStream(Files.java:220)
	at org.eclipse.jetty.webapp/org.eclipse.jetty.webapp.WebAppDefaultServletTest.prepareServer(WebAppDefaultServletTest.java:84)

 + As is typical on windows, we are often unable to delete a file due to file locking issues.
 + Use a unique resource base between tests.
   This is to avoid file locking behaviors that prevent the
   resource base from being reused too quickly on windows.
 + Prevent test run if symlinks not supported
 + Allowing for Windows slosh char as well in asserts
 + SelectorUtils is File.separator dependent
 + Regex is now FS.separator independent
 + Using SelectorUtils from plexus correctly for include/exclude
 + Turning off mapped files for testing reasons.
 + Fix and re-enable RFC2616NIOHttpsTest
 + Issue #6552 - Fix test failures due to slf4j dep
 + Issue #6552 - upgrade testcontainers
 + Issue #6552 - move to assumption based docker existence
 + Issue #6552 - Fix enforcer rule violation on jna.
  Addresses the following side effect of upgrading testcontainers.

[WARNING] Rule 3: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
Failed while enforcing RequireUpperBoundDeps. The error(s) are [
Require upper bound dependencies error for net.java.dev.jna:jna:5.6.0 paths to dependency are:
+-org.eclipse.jetty:infinispan-remote-query:10.0.7-SNAPSHOT
  +-org.testcontainers:testcontainers:1.16.0
    +-com.github.docker-java:docker-java-transport-zerodep:3.2.11
      +-net.java.dev.jna:jna:5.6.0 (managed) <-- net.java.dev.jna:jna:5.8.0

 + use annotation to disable test when docker not available and needed
 + Disabling FileSessionDistributionTests.stopRestartWebappTestSessionContentSaved on Windows
 + Using TLS basic
 + Programmatic removal of memory mapped behavior during testing
 + Fixing slf4j warning

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Co-authored-by: Olivier Lamy <oliver.lamy@gmail.com>
  • Loading branch information
joakime and olamy committed Aug 26, 2021
1 parent 2689cf7 commit c5a33e2
Show file tree
Hide file tree
Showing 55 changed files with 463 additions and 423 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.JRE;
Expand All @@ -82,7 +81,6 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.condition.OS.LINUX;
import static org.junit.jupiter.api.condition.OS.WINDOWS;

// Other JREs have slight differences in how TLS work
// and this test expects a very specific TLS behavior.
Expand Down Expand Up @@ -1027,7 +1025,6 @@ record = proxy.readFromServer();
}

@Test
@DisabledOnOs(WINDOWS) // Don't run on Windows (buggy JVM)
public void testRequestWithBigContentWriteBlockedThenReset() throws Exception
{
final SSLSocket client = newClient();
Expand Down Expand Up @@ -1082,7 +1079,6 @@ public void testRequestWithBigContentWriteBlockedThenReset() throws Exception
}

@Test
@DisabledOnOs(WINDOWS) // Don't run on Windows (buggy JVM)
public void testRequestWithBigContentReadBlockedThenReset() throws Exception
{
final SSLSocket client = newClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,57 @@
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.Scanner;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

@ExtendWith(WorkDirExtension.class)
public class DeploymentTempDirTest
{
private static final Logger LOG = Log.getLogger(DeploymentTempDirTest.class);

private final WebAppProvider webAppProvider = new WebAppProvider();
private final ContextHandlerCollection contexts = new ContextHandlerCollection();
private final Path testDir = MavenTestingUtils.getTargetTestingPath(DeploymentTempDirTest.class.getSimpleName());
private final Path tmpDir = testDir.resolve("tmpDir");
private final Path webapps = testDir.resolve("webapps");
private final Server server = new Server();
public WorkDir workDir;

private Path tmpDir;
private Path webapps;
private Server server;
private WebAppProvider webAppProvider;
private ContextHandlerCollection contexts;
private final TestListener listener = new TestListener();

@BeforeEach
public void setup() throws Exception
{
Path testDir = workDir.getEmptyPathDir();
tmpDir = testDir.resolve("tmpDir");
webapps = testDir.resolve("webapps");

FS.ensureDirExists(tmpDir);
FS.ensureDirExists(webapps);

server = new Server();

ServerConnector connector = new ServerConnector(server);
server.addConnector(connector);

FS.ensureEmpty(testDir);
FS.ensureEmpty(tmpDir);
FS.ensureEmpty(webapps);
webAppProvider = new WebAppProvider();

webAppProvider.setMonitoredDirName(webapps.toString());
webAppProvider.setScanInterval(0);
DeploymentManager deploymentManager = new DeploymentManager();
deploymentManager.addAppProvider(webAppProvider);
server.addBean(deploymentManager);

contexts = new ContextHandlerCollection();
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.addHandler(contexts);
handlerCollection.addHandler(new DefaultHandler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.junit.jupiter.api.condition.OS.WINDOWS;

/**
* Similar in scope to {@link ScanningAppProviderStartupTest}, except is concerned with the modification of existing
* deployed webapps due to incoming changes identified by the {@link ScanningAppProvider}.
Expand Down Expand Up @@ -155,8 +152,6 @@ public void testAfterStartupThenRemoveContext() throws IOException
* @throws Exception on test failure
*/
@Test
@DisabledOnOs(WINDOWS)
// This test will not work on Windows as second war file would, not be written over the first one because of a file lock
public void testAfterStartupThenUpdateContext() throws Exception
{
jetty.copyWebapp("foo-webapp-1.war", "foo.war");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public void teardownEnvironment() throws Exception
@Test
public void testStartupContext()
{
assumeTrue(symlinkSupported);

// Check Server for Handlers
jetty.assertWebAppContextsExists("/bar", "/foo", "/bob");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Promise;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;

import static org.junit.jupiter.api.Assertions.assertTrue;

@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Unable to create all of the streams")
public class ConcurrentStreamCreationTest extends AbstractTest
{
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ private boolean run(Session session, int iterations)
Thread testThread = Thread.currentThread();
Scheduler.Task task = client.getScheduler().schedule(() ->
{
logger.warn("Interrupting test, it is taking too long{}Server:{}{}{}Client:{}{}",
System.lineSeparator(), System.lineSeparator(), server.dump(),
System.lineSeparator(), System.lineSeparator(), client.dump());
logger.warn("Interrupting test, it is taking too long - \nServer: \n" +
server.dump() + "\nClient: \n" + client.dump());
testThread.interrupt();
}, iterations * factor, TimeUnit.MILLISECONDS);

Expand Down Expand Up @@ -184,9 +183,8 @@ public void onReset(Stream stream, ResetFrame frame)
if (success)
latch.countDown();
else
logger.warn("Request {} took too long{}Server:{}{}{}Client:{}{}", requestId,
System.lineSeparator(), System.lineSeparator(), server.dump(),
System.lineSeparator(), System.lineSeparator(), client.dump());
logger.warn("Request {} took too long - \nServer: \n" +
server.dump() + "\nClient: \n" + client.dump(), requestId);
return !reset.get();
}

Expand Down
5 changes: 5 additions & 0 deletions jetty-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@
<artifactId>maven-artifact-transfer</artifactId>
<version>0.12.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import org.codehaus.plexus.util.SelectorUtils;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.JarResource;
import org.slf4j.Logger;
Expand Down Expand Up @@ -87,7 +86,7 @@ protected boolean isIncluded(String name)
{
for (String include : _includes)
{
if (SelectorUtils.matchPath(include, name, _caseSensitive))
if (SelectorUtils.matchPath(include, name, "/", _caseSensitive))
{
return true;
}
Expand All @@ -99,7 +98,7 @@ protected boolean isExcluded(String name)
{
for (String exclude : _excludes)
{
if (SelectorUtils.matchPath(exclude, name, _caseSensitive))
if (SelectorUtils.matchPath(exclude, name, "/", _caseSensitive))
{
return true;
}
Expand Down Expand Up @@ -140,8 +139,8 @@ public void copyTo(File directory) throws IOException
String entryName = entry.getName();

LOG.debug("Looking at {}", entryName);
String dotCheck = StringUtil.replace(entryName, '\\', '/');
dotCheck = URIUtil.canonicalPath(dotCheck);
// make sure no access out of the root entry is present
String dotCheck = URIUtil.canonicalPath(entryName);
if (dotCheck == null)
{
LOG.info("Invalid entry: {}", entryName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,96 +13,81 @@

package org.eclipse.jetty.maven.plugin;

import java.io.File;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.resource.Resource;
import org.junit.jupiter.api.BeforeEach;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
*
*
*/
@ExtendWith(WorkDirExtension.class)
public class TestSelectiveJarResource
{
File unpackParent;

@BeforeEach
public void setUp() throws Exception
{
unpackParent = MavenTestingUtils.getTargetTestingDir("selective-jar-resource");
unpackParent.mkdirs();
}

public WorkDir workDir;

@Test
public void testIncludesNoExcludes() throws Exception
{
File unpackDir = File.createTempFile("inc", "exc", unpackParent);
unpackDir.delete();
unpackDir.mkdirs();
Path unpackDir = workDir.getEmptyPathDir();

File testJar = MavenTestingUtils.getTestResourceFile("selective-jar-test.jar");
try (SelectiveJarResource sjr = new SelectiveJarResource(new URL("jar:" + Resource.toURL(testJar).toString() + "!/"));)
Path testJar = MavenTestingUtils.getTestResourcePathFile("selective-jar-test.jar");
try (SelectiveJarResource sjr = new SelectiveJarResource(new URL("jar:" + testJar.toUri().toASCIIString() + "!/")))
{
sjr.setCaseSensitive(false);
List<String> includes = new ArrayList<>();
includes.add("**/*.html");
sjr.setIncludes(includes);
sjr.copyTo(unpackDir);
assertTrue(Files.exists(unpackDir.toPath().resolve("top.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("aa/a1.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("aa/a2.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("aa/deep/a3.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("bb/b1.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("bb/b2.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("cc/c1.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("cc/c2.html")));
sjr.copyTo(unpackDir.toFile());
assertTrue(Files.exists(unpackDir.resolve("top.html")));
assertTrue(Files.exists(unpackDir.resolve("aa/a1.html")));
assertTrue(Files.exists(unpackDir.resolve("aa/a2.html")));
assertTrue(Files.exists(unpackDir.resolve("aa/deep/a3.html")));
assertTrue(Files.exists(unpackDir.resolve("bb/b1.html")));
assertTrue(Files.exists(unpackDir.resolve("bb/b2.html")));
assertTrue(Files.exists(unpackDir.resolve("cc/c1.html")));
assertTrue(Files.exists(unpackDir.resolve("cc/c2.html")));
}
}

@Test
public void testExcludesNoIncludes() throws Exception
{
File unpackDir = File.createTempFile("exc", "inc", unpackParent);
unpackDir.delete();
unpackDir.mkdirs();
File testJar = MavenTestingUtils.getTestResourceFile("selective-jar-test.jar");

try (SelectiveJarResource sjr = new SelectiveJarResource(new URL("jar:" + Resource.toURL(testJar).toString() + "!/"));)
Path unpackDir = workDir.getEmptyPathDir();

Path testJar = MavenTestingUtils.getTestResourcePathFile("selective-jar-test.jar");
try (SelectiveJarResource sjr = new SelectiveJarResource(new URL("jar:" + testJar.toUri().toASCIIString() + "!/")))
{
sjr.setCaseSensitive(false);
List<String> excludes = new ArrayList<>();
excludes.add("**/*");
sjr.setExcludes(excludes);
sjr.copyTo(unpackDir);
assertFalse(Files.exists(unpackDir.toPath().resolve("top.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("aa/a1.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("aa/a2.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("aa/deep/a3.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("bb/b1.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("bb/b2.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("cc/c1.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("cc/c2.html")));
sjr.copyTo(unpackDir.toFile());
assertFalse(Files.exists(unpackDir.resolve("top.html")));
assertFalse(Files.exists(unpackDir.resolve("aa/a1.html")));
assertFalse(Files.exists(unpackDir.resolve("aa/a2.html")));
assertFalse(Files.exists(unpackDir.resolve("aa/deep/a3.html")));
assertFalse(Files.exists(unpackDir.resolve("bb/b1.html")));
assertFalse(Files.exists(unpackDir.resolve("bb/b2.html")));
assertFalse(Files.exists(unpackDir.resolve("cc/c1.html")));
assertFalse(Files.exists(unpackDir.resolve("cc/c2.html")));
}
}

@Test
public void testIncludesExcludes() throws Exception
{
File unpackDir = File.createTempFile("exc", "andinc", unpackParent);
unpackDir.delete();
unpackDir.mkdirs();
File testJar = MavenTestingUtils.getTestResourceFile("selective-jar-test.jar");

try (SelectiveJarResource sjr = new SelectiveJarResource(new URL("jar:" + Resource.toURL(testJar).toString() + "!/"));)
Path unpackDir = workDir.getEmptyPathDir();

Path testJar = MavenTestingUtils.getTestResourcePathFile("selective-jar-test.jar");
try (SelectiveJarResource sjr = new SelectiveJarResource(new URL("jar:" + testJar.toUri().toASCIIString() + "!/")))
{
sjr.setCaseSensitive(false);
List<String> excludes = new ArrayList<>();
Expand All @@ -111,15 +96,15 @@ public void testIncludesExcludes() throws Exception
List<String> includes = new ArrayList<>();
includes.add("bb/*");
sjr.setIncludes(includes);
sjr.copyTo(unpackDir);
assertFalse(Files.exists(unpackDir.toPath().resolve("top.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("aa/a1.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("aa/a2.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("aa/deep/a3.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("bb/b1.html")));
assertTrue(Files.exists(unpackDir.toPath().resolve("bb/b2.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("cc/c1.html")));
assertFalse(Files.exists(unpackDir.toPath().resolve("cc/c2.html")));
sjr.copyTo(unpackDir.toFile());
assertFalse(Files.exists(unpackDir.resolve("top.html")));
assertFalse(Files.exists(unpackDir.resolve("aa/a1.html")));
assertFalse(Files.exists(unpackDir.resolve("aa/a2.html")));
assertFalse(Files.exists(unpackDir.resolve("aa/deep/a3.html")));
assertTrue(Files.exists(unpackDir.resolve("bb/b1.html")));
assertTrue(Files.exists(unpackDir.resolve("bb/b2.html")));
assertFalse(Files.exists(unpackDir.resolve("cc/c1.html")));
assertFalse(Files.exists(unpackDir.resolve("cc/c2.html")));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Jetty Logging using jetty-slf4j-impl
#org.eclipse.jetty.maven.plugin.LEVEL=DEBUG
#org.eclipse.jetty.LEVEL=DEBUG
#org.eclipse.jetty.server.LEVEL=DEBUG
#org.eclipse.jetty.http.LEVEL=DEBUG
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ public boolean transform(Source source, Sink sink)
startClient();

ContentResponse response = client.newRequest("localhost", serverConnector.getLocalPort())
.timeout(5, TimeUnit.SECONDS)
.timeout(10, TimeUnit.SECONDS)
.send();

assertEquals(200, response.getStatus());
Expand Down

0 comments on commit c5a33e2

Please sign in to comment.