From a5ffd0c2d4ea55a1f251ff237c564b2416d08354 Mon Sep 17 00:00:00 2001 From: Christoph Kutzinski Date: Sat, 19 Nov 2011 21:39:08 +0100 Subject: [PATCH] modify latch to use CountDownLatch and wait 30 seconds more for builds as test likes to time-out a lot --- .../hudson/slaves/NodeProvisionerTest.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/test/src/test/java/hudson/slaves/NodeProvisionerTest.java b/test/src/test/java/hudson/slaves/NodeProvisionerTest.java index aff97acc4c..ba582c1a09 100644 --- a/test/src/test/java/hudson/slaves/NodeProvisionerTest.java +++ b/test/src/test/java/hudson/slaves/NodeProvisionerTest.java @@ -28,6 +28,8 @@ import hudson.Launcher; import hudson.model.*; import hudson.slaves.NodeProvisioner.NodeProvisionerInvoker; import hudson.tasks.Builder; +import hudson.util.TimeUnit2; + import org.jvnet.hudson.test.HudsonTestCase; import org.jvnet.hudson.test.SleepBuilder; @@ -35,6 +37,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -69,16 +72,17 @@ public class NodeProvisionerTest extends HudsonTestCase { */ static class Latch { /** Initial value */ - public final int init; - private int n; + public final CountDownLatch counter; + private final int init; Latch(int n) { - this.n = init = n; + this.init = n; + this.counter = new CountDownLatch(n); } - synchronized void block() throws InterruptedException { - if(--n==0) notifyAll(); // wake up everyone else - else wait(60*1000); // if a test takes t oo long, abort. + void block() throws InterruptedException { + this.counter.countDown(); + this.counter.await(60, TimeUnit.SECONDS); } /** @@ -232,7 +236,7 @@ public class NodeProvisionerTest extends HudsonTestCase { System.out.println("Waiting for a completion"); for (Future f : builds) { try { - assertBuildStatus(Result.SUCCESS, f.get(60, TimeUnit.SECONDS)); + assertBuildStatus(Result.SUCCESS, f.get(90, TimeUnit.SECONDS)); } catch (TimeoutException e) { // time out so that the automated test won't hang forever, even when we have bugs System.out.println("Build didn't complete in time"); -- GitLab