Skip to content

Commit

Permalink
Stop swallowing exceptions that happen in TestEnvironment.dispose
Browse files Browse the repository at this point in the history
This commit is excepted to reveal bogus tests that do not properly shutdown,
especially on Windows where directory cannot be removed if there are any running processes
that use it as a working directory.
  • Loading branch information
slonopotamus committed Sep 23, 2019
1 parent 4f8ea2c commit a07387a
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/main/java/org/jvnet/hudson/test/JenkinsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,21 +509,19 @@ public void after() throws Exception {

try {
env.dispose();
} catch (Exception x) {
x.printStackTrace();
}

// Hudson creates ClassLoaders for plugins that hold on to file descriptors of its jar files,
// but because there's no explicit dispose method on ClassLoader, they won't get GC-ed until
// at some later point, leading to possible file descriptor overflow. So encourage GC now.
// see http://bugs.sun.com/view_bug.do?bug_id=4950148
// TODO use URLClassLoader.close() in Java 7
System.gc();

// restore defaultUseCache
if(Functions.isWindows()) {
URLConnection aConnection = new File(".").toURI().toURL().openConnection();
aConnection.setDefaultUseCaches(origDefaultUseCache);
} finally {
// Hudson creates ClassLoaders for plugins that hold on to file descriptors of its jar files,
// but because there's no explicit dispose method on ClassLoader, they won't get GC-ed until
// at some later point, leading to possible file descriptor overflow. So encourage GC now.
// see http://bugs.sun.com/view_bug.do?bug_id=4950148
// TODO use URLClassLoader.close() in Java 7
System.gc();

// restore defaultUseCache
if(Functions.isWindows()) {
URLConnection aConnection = new File(".").toURI().toURL().openConnection();
aConnection.setDefaultUseCaches(origDefaultUseCache);
}
}
}
}
Expand Down

0 comments on commit a07387a

Please sign in to comment.