jenkinsci / jenkins-test-harness

Unit test framework for Jenkins core and its plugins
https://www.jenkins.io/doc/developer/testing/
MIT License
110 stars 130 forks source link

Improved use of `java.io.tmpdir` #838

Closed jglick closed 2 months ago

jglick commented 2 months ago

Ensure that temporary files are written to target/tmp/ (where mvn clean can delete them) rather than the system temporary directory, including in RealJenkinsRule forked JVMs; note that in the test JVM it seems to be necessary to look up this system property explicitly, I think since Surefire sets the system property after startup rather than using -D, and something reads and caches the value soon after startup. Ensure that all temporary directories are deleted when the test exits. Use temporary directories instead of $JENKINS_HOME for anything added by the test harness rather than Jenkins itself. (Extracted from #827.)

basil commented 2 months ago
java.lang.AssertionError
    at org.junit.Assert.fail(Assert.java:87)
    at org.junit.Assert.assertTrue(Assert.java:42)
    at org.junit.Assert.assertTrue(Assert.java:53)
    at hudson.PluginManagerTest.uberClassLoaderIsAvailableDuringStart(PluginManagerTest.java:213)
org.jvnet.hudson.test.RealJenkinsRule$StepException: 
Remote step threw an exception: java.lang.AssertionError: 
Expected: is "/home/jenkins/agent/workspace/Core_jenkins_PR-9756/test/target/j h7251048736527506496/agent.jar"
     but: was "/home/jenkins/agent/workspace/Core_jenkins_PR-9756/test/target/agent.jar"
    at org.jvnet.hudson.test.RealJenkinsRule.runRemotely(RealJenkinsRule.java:998)
    at org.jvnet.hudson.test.RealJenkinsRule.runRemotely(RealJenkinsRule.java:983)
    at hudson.slaves.JNLPLauncherRealTest.then(JNLPLauncherRealTest.java:81)
    at hudson.slaves.JNLPLauncherRealTest.webSocket(JNLPLauncherRealTest.java:70)
    at java.base/java.lang.reflect.Method.invoke(Method.java:569)
    at org.jvnet.hudson.test.RealJenkinsRule$1.evaluate(RealJenkinsRule.java:527)
Caused by: java.lang.AssertionError: 
Expected: is "/home/jenkins/agent/workspace/Core_jenkins_PR-9756/test/target/j h7251048736527506496/agent.jar"
     but: was "/home/jenkins/agent/workspace/Core_jenkins_PR-9756/test/target/agent.jar"
    at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
    at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:6)
    at hudson.slaves.JNLPLauncherRealTest$RunJobStep.run(JNLPLauncherRealTest.java:107)
    at org.jvnet.hudson.test.RealJenkinsRule$StepsToStep2.run(RealJenkinsRule.java:1419)
    at org.jvnet.hudson.test.RealJenkinsRule$Endpoint.lambda$doStep$0(RealJenkinsRule.java:1332)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:840)