I have noticed that the HudsonTestCase sometimes does not do a proper clean up
      of the temp folders. On Windows this happens every time because of a file in use
      error. On Linux (debian) this sometimes happen if a test fails. As the temp
      folder can contain up to 14mbs, the total size can grow quickly.

      After 1 month of developing/testing my hudson test case folders consisted of
      500+k files in 892 folders, amounting to 7+Gb. (Windows)

      Maybe we can use the new TemporaryFolder rule that is available in JUnit 4.7, so
      we can lift out stuff from our implementation? http://github.com/KentBeck/junit/raw/23ffc6baf5768057e366e183e53f4dfa86fbb005/do
      c/ReleaseNotes4.7.txt

      Steps to reproduce on linux:
      1. Clean out all hudsonXXXX folders in the temp folder
      2. Go to hudson/plugins/seleniuma
      3. run "mvn test" and watch it fail
      4. Check the temp folder

      Expected result:
      No new folder in the temp folder

      Actual Result:
      A folder named hudsonXXXXXXX has been created

      Steps to reproduce:
      1. Go to hudson/plugins/ci-game
      2. run "mvn test"
      3. Watch output

      Expected result:
      Test fails

      Actual Result:
      An exception is thrown during the test clean up:

      java.io.IOException: Unable to delete
      C:\DOCUME~1\name\LOCALS~1\Temp\hudson40664test\plugins\maven-plugin\WEB-INF\lib\
      classworlds-1.1.jar
      at hudson.Util.deleteFile(Util.java:225)
      at hudson.Util.deleteRecursive(Util.java:257)
      at hudson.Util.deleteContentsRecursive(Util.java:186)
      at hudson.Util.deleteRecursive(Util.java:256)
      at hudson.Util.deleteContentsRecursive(Util.java:186)
      at hudson.Util.deleteRecursive(Util.java:256)
      at hudson.Util.deleteContentsRecursive(Util.java:186)
      at hudson.Util.deleteRecursive(Util.java:256)
      at hudson.Util.deleteContentsRecursive(Util.java:186)
      at hudson.Util.deleteRecursive(Util.java:256)
      at hudson.Util.deleteContentsRecursive(Util.java:186)
      at hudson.Util.deleteRecursive(Util.java:256)
      at hudson.FilePath$9.invoke(FilePath.java:748)
      at hudson.FilePath$9.invoke(FilePath.java:746)
      at hudson.FilePath.act(FilePath.java:676)
      at hudson.FilePath.act(FilePath.java:660)
      at hudson.FilePath.deleteRecursive(FilePath.java:746)
      at
      org.jvnet.hudson.test.TemporaryDirectoryAllocator$1.run(TemporaryDirectoryAlloca
      tor.java:90)

          [JENKINS-4409] Hudson test case leaks temp folders

          redsolo created issue -

          Andrew Bayer added a comment -
              • Issue 4249 has been marked as a duplicate of this issue. ***

          Andrew Bayer added a comment - Issue 4249 has been marked as a duplicate of this issue. ***
          Andrew Bayer made changes -
          Link New: This issue is duplicated by JENKINS-4249 [ JENKINS-4249 ]

          Alan Harder added a comment -

          I've noticed another case where the temp folder for the last test to run does
          not get removed. This appears to be because TestEnvironment.dispose() calls
          TemporaryDirectoryAllocator.disposeAsync() and the tests exit before this thread
          completes (even though it is not a daemon thread). I see this on OSX.

          Alan Harder added a comment - I've noticed another case where the temp folder for the last test to run does not get removed. This appears to be because TestEnvironment.dispose() calls TemporaryDirectoryAllocator.disposeAsync() and the tests exit before this thread completes (even though it is not a daemon thread). I see this on OSX.
          Simon Westcott made changes -
          Link New: This issue is related to JENKINS-12328 [ JENKINS-12328 ]

          Roland Gruber added a comment -

          Problem still exists.

          Roland Gruber added a comment - Problem still exists.

          ikedam added a comment -

          In my environment, the output becomes like this:

          ...
          Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 30.876 sec
          Failed to load native POSIX impl; falling back on Java impl. Unsupported OS.
          java.io.IOException: Unable to delete C:\Users\user\AppData\Local\Temp\hudson4413809435965306193tmp\credentials\WEB-INF\lib\findbugs-annotations-1.3.9-1.jar
          	at hudson.Util.deleteFile(Util.java:256)
          	at hudson.Util.deleteRecursive(Util.java:308)
          	at hudson.Util.deleteContentsRecursive(Util.java:205)
          	at hudson.Util.deleteRecursive(Util.java:299)
          	at hudson.Util.deleteContentsRecursive(Util.java:205)
          	at hudson.Util.deleteRecursive(Util.java:299)
          	at hudson.Util.deleteContentsRecursive(Util.java:205)
          	at hudson.Util.deleteRecursive(Util.java:299)
          	at hudson.Util.deleteContentsRecursive(Util.java:205)
          	at hudson.Util.deleteRecursive(Util.java:299)
          	at org.jvnet.hudson.test.TestPluginManager$1.run(TestPluginManager.java:130)
          
          Results :
          
          Tests run: 7, Failures: 0, Errors: 0, Skipped: 0
          
          [INFO] ------------------------------------------------------------------------
          [INFO] BUILD SUCCESS
          [INFO] ------------------------------------------------------------------------
          
          • The test succeeds, but fails to delete the temporary folder.
          • TestPluginManager seems to expand common plugins to the temporary folder used by Jenkins instance for the test.
          • For JVM holds handles of jar files, the shutdown hook registered by TestPluginManager fails to delete the temporary directory.

          ikedam added a comment - In my environment, the output becomes like this: ... Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 30.876 sec Failed to load native POSIX impl; falling back on Java impl. Unsupported OS. java.io.IOException: Unable to delete C:\Users\user\AppData\Local\Temp\hudson4413809435965306193tmp\credentials\WEB-INF\lib\findbugs-annotations-1.3.9-1.jar at hudson.Util.deleteFile(Util.java:256) at hudson.Util.deleteRecursive(Util.java:308) at hudson.Util.deleteContentsRecursive(Util.java:205) at hudson.Util.deleteRecursive(Util.java:299) at hudson.Util.deleteContentsRecursive(Util.java:205) at hudson.Util.deleteRecursive(Util.java:299) at hudson.Util.deleteContentsRecursive(Util.java:205) at hudson.Util.deleteRecursive(Util.java:299) at hudson.Util.deleteContentsRecursive(Util.java:205) at hudson.Util.deleteRecursive(Util.java:299) at org.jvnet.hudson.test.TestPluginManager$1.run(TestPluginManager.java:130) Results : Tests run: 7, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ The test succeeds, but fails to delete the temporary folder. TestPluginManager seems to expand common plugins to the temporary folder used by Jenkins instance for the test. For JVM holds handles of jar files, the shutdown hook registered by TestPluginManager fails to delete the temporary directory.

          ikedam added a comment - - edited

          I verified that following code resolves the problem:

          // when your test classes run with JenkinsRule:
              @Rule
              public JenkinsRule j = new JenkinsRule(){
                  protected void before() throws Throwable {
                      setPluginManager(null);
                      super.before();
                  }
              };
          
          // when your test classes derived from HudsonTestCase:
              @Override
              protected void setUp() throws Exception
              {
                  setPluginManager(null);
                  super.setUp();
              }
          
          • This takes effects only when running with -Dtest=(test class)
          • When run as "mvn test" (without -Dtest=XXXX), InjectTests runs and TestPluginManager is used.

          ikedam added a comment - - edited I verified that following code resolves the problem: // when your test classes run with JenkinsRule: @Rule public JenkinsRule j = new JenkinsRule(){ protected void before() throws Throwable { setPluginManager( null ); super .before(); } }; // when your test classes derived from HudsonTestCase: @Override protected void setUp() throws Exception { setPluginManager( null ); super .setUp(); } This takes effects only when running with -Dtest=(test class) When run as "mvn test" (without -Dtest=XXXX), InjectTests runs and TestPluginManager is used.

          ikedam added a comment -

          Stop InjectedTests with following in pom.xml:

            <build>
              <plugins>
                <plugin>
                  <groupId>org.jenkins-ci.tools</groupId>
                  <artifactId>maven-hpi-plugin</artifactId>
                  <extensions>true</extensions>
                  <configuration>
                    <disabledTestInjection>true</disabledTestInjection>
                  </configuration>
                </plugin>
              </plugins>
            </build>
          

          ikedam added a comment - Stop InjectedTests with following in pom.xml: <build> <plugins> <plugin> <groupId>org.jenkins-ci.tools</groupId> <artifactId>maven-hpi-plugin</artifactId> <extensions> true </extensions> <configuration> <disabledTestInjection> true </disabledTestInjection> </configuration> </plugin> </plugins> </build>

          ikedam added a comment -
          • ${java.io.tmp}/hudsonXXXXtest
            • Not deleted with JenkinsRule in Jenkins < 1.482 (5dd905f2a2)
          • ${java.io.tmp}/hudsonXXXXtmp
            • Not deleted with Jenkins < 1.510 (a4d4305124)
            • Fails to be deleted with Jenkins >= 1.510

          ikedam added a comment - ${java.io.tmp}/hudsonXXXXtest Not deleted with JenkinsRule in Jenkins < 1.482 ( 5dd905f2a2 ) ${java.io.tmp}/hudsonXXXXtmp Not deleted with Jenkins < 1.510 ( a4d4305124 ) Fails to be deleted with Jenkins >= 1.510

            ikedam ikedam
            redsolo redsolo
            Votes:
            4 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: