jetty.project icon indicating copy to clipboard operation
jetty.project copied to clipboard

DispatcherTest.testForwardToWelcome() fails in ee9/ee8 if surefire reuseForks=true

Open joakime opened this issue 1 year ago • 0 comments

Jetty version(s) 12.0.10

Jetty Environment ee9 / ee8

Java version/vendor (use: java -version) Any

OS type/version Any

Description When working on PR #11930 it was discovered that the ee9 / ee8 (not ee10) DispatcherTests are failing in the following way ...

Stacktrace:

java.lang.AssertionError: 
Expected: a string containing "HTTP/1.1 302 Found"
     but: was "HTTP/1.1 200 OK
Last-Modified: Thu, 20 Jun 2024 21:16:47 GMT
Accept-Ranges: bytes
Content-Length: 4096
Connection: close
index.html
"
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:6)
	at [email protected]/org.eclipse.jetty.ee9.servlet.DispatcherTest.testForwardToWelcome(DispatcherTest.java:159)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

Standard Error

Running org.eclipse.jetty.ee9.servlet.DispatcherTest.testForwardToWelcome()
2024-06-20 21:45:04.094:INFO :oejs.Server:ForkJoinPool-1-worker-3: jetty-12.0.11-SNAPSHOT; built: 2024-06-20T21:17:46.344Z; git: ce6174f9ff9dba9fcc68859880d17c9a16a1401e; jvm 21.0.1+12-LTS
2024-06-20 21:45:04.095:INFO :oejsh.ContextHandler:ForkJoinPool-1-worker-3: Started oeje9n.ContextHandler$CoreContextHandler@661cd22a{/context,/context,b=(URL) file:///home/jenkins/agent/workspace/jetty.project_PR-11930/jetty-ee9/jetty-ee9-servlet/src/test/resources/contextResources/,a=AVAILABLE,h=oeje9n.ContextHandler$CoreContextHandler$CoreToNestedHandler@64c64de3{STARTED}}
2024-06-20 21:45:04.095:INFO :oejsh.ContextHandler:ForkJoinPool-1-worker-3: Started oeje9n.ContextHandler$CoreContextHandler@c8de777{/resource,/resource,b=null,a=AVAILABLE,h=oeje9n.ContextHandler$CoreContextHandler$CoreToNestedHandler@5af20a50{STARTED}}
2024-06-20 21:45:04.095:INFO :oejs.AbstractConnector:ForkJoinPool-1-worker-3: Started LocalConnector@71e78163{HTTP/1.1, (http/1.1)}
2024-06-20 21:45:04.095:INFO :oejs.Server:ForkJoinPool-1-worker-3: Started oejs.Server@3c129861{STARTING}[12.0.11-SNAPSHOT,sto=0] @7303ms
2024-06-20 21:45:04.099:INFO :oejs.Server:ForkJoinPool-1-worker-3: Stopped oejs.Server@3c129861{STOPPING}[12.0.11-SNAPSHOT,sto=0]
2024-06-20 21:45:04.099:INFO :oejs.AbstractConnector:ForkJoinPool-1-worker-3: Stopped LocalConnector@71e78163{HTTP/1.1, (http/1.1)}

That PR disabled the surefire reuseForks to get past this issue.

https://github.com/jetty/jetty.project/blob/f78f4422f5913820bead90cfa7a337415ff8935d/jetty-ee9/jetty-ee9-servlet/pom.xml#L73-L76

Turns out there is some unintended interaction between test cases when resuseForks = true.

To replicate, just set <reuseForks>true</reuseForks> in the surefire config on project /ee9/jetty-ee9-servlet/ and then run mvn clean install -pl :jetty-ee9-servlet to build & run all tests. It will fail, reliably, with the above stacktrace.

But if you run just the DispatcherTest it works reliably 100% of the time.

In talking with @olamy the current theory is that there is some kind of static field / class / instance that is hanging around between runs on the same fork that is impacting the execution of DispatcherTest in particular.

joakime avatar Jun 25 '24 13:06 joakime