From a70f6b19aedfb6fb454aaf1c8789d94e6c72da99 Mon Sep 17 00:00:00 2001 From: Jerome Lacoste Date: Fri, 4 Feb 2011 21:36:25 +0100 Subject: [PATCH] JENKINS-8698 HudsonTestCase sometimes fails with NPE in tearDown() while trying to free htmlunit resources Not really sure what is happening, but I don't think the build should fail here. So let's try to be more resiliant (try twice loading the page) and don't fail if the exception occurs again. --- .../java/org/jvnet/hudson/test/HudsonTestCase.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 2fba0401a9..adc5d89199 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -294,7 +294,7 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { WebClient c = client.get(); if(c==null) continue; // unload the page to cancel asynchronous operations - c.getPage("about:blank"); + safeUnloadPage(c, 2); } clients.clear(); } finally { @@ -315,6 +315,16 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { } } + private void safeUnloadPage(WebClient c, int maxTries) { + if (maxTries == 0) return; + try{ + c.getPage("about:blank"); + } catch(Exception e){ + e.printStackTrace(); + safeUnloadPage(c, maxTries--); + } + } + @Override protected void runTest() throws Throwable { System.out.println("=== Starting "+ getClass().getSimpleName() + "." + getName());