From 88857a6f6c94f0328c77bc852c63835da8485c38 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 1 Sep 2009 21:57:49 +0000 Subject: [PATCH] avoid "2nd instance" test failures. The stack trace was: java.lang.NullPointerException at com.gargoylesoftware.htmlunit.html.HtmlPage.loadFrames(HtmlPage.java:1732) at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:153) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:455) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:340) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:390) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:377) at org.jvnet.hudson.test.HudsonTestCase$WebClient.getPage(HudsonTestCase.java:1002) at org.jvnet.hudson.test.HudsonTestCase.tearDown(HudsonTestCase.java:257) at junit.framework.TestCase.runBare(TestCase.java:130) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at sun.reflect.GeneratedMethodAccessor232.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127) at org.apache.maven.surefire.Surefire.run(Surefire.java:177) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345) at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009) git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@21328 71c3de6d-444a-0410-be80-ed276b4c234a --- .../org/jvnet/hudson/test/HudsonTestCase.java | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index 89ef1797a9..1af7a91e20 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -249,29 +249,31 @@ public abstract class HudsonTestCase extends TestCase { } protected void tearDown() throws Exception { - // cancel pending asynchronous operations, although this doesn't really seem to be working - for (WeakReference client : clients) { - WebClient c = client.get(); - if(c==null) continue; - // unload the page to cancel asynchronous operations - c.getPage("about:blank"); + try { + // cancel pending asynchronous operations, although this doesn't really seem to be working + for (WeakReference client : clients) { + WebClient c = client.get(); + if(c==null) continue; + // unload the page to cancel asynchronous operations + c.getPage("about:blank"); + } + clients.clear(); + } finally { + server.stop(); + for (LenientRunnable r : tearDowns) + r.run(); + + hudson.cleanUp(); + env.dispose(); + ExtensionList.clearLegacyInstances(); + DescriptorExtensionList.clearLegacyInstances(); + + // 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 + System.gc(); } - clients.clear(); - - server.stop(); - for (LenientRunnable r : tearDowns) - r.run(); - - hudson.cleanUp(); - env.dispose(); - ExtensionList.clearLegacyInstances(); - DescriptorExtensionList.clearLegacyInstances(); - - // 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 - System.gc(); } protected void runTest() throws Throwable { -- GitLab