提交 a5ffd0c2 编写于 作者: C Christoph Kutzinski

modify latch to use CountDownLatch and wait 30 seconds more for builds as test...

modify latch to use CountDownLatch and wait 30 seconds more for builds as test likes to time-out a lot
上级 eb1e08c5
...@@ -28,6 +28,8 @@ import hudson.Launcher; ...@@ -28,6 +28,8 @@ import hudson.Launcher;
import hudson.model.*; import hudson.model.*;
import hudson.slaves.NodeProvisioner.NodeProvisionerInvoker; import hudson.slaves.NodeProvisioner.NodeProvisionerInvoker;
import hudson.tasks.Builder; import hudson.tasks.Builder;
import hudson.util.TimeUnit2;
import org.jvnet.hudson.test.HudsonTestCase; import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.SleepBuilder; import org.jvnet.hudson.test.SleepBuilder;
...@@ -35,6 +37,7 @@ import java.io.IOException; ...@@ -35,6 +37,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
...@@ -69,16 +72,17 @@ public class NodeProvisionerTest extends HudsonTestCase { ...@@ -69,16 +72,17 @@ public class NodeProvisionerTest extends HudsonTestCase {
*/ */
static class Latch { static class Latch {
/** Initial value */ /** Initial value */
public final int init; public final CountDownLatch counter;
private int n; private final int init;
Latch(int n) { Latch(int n) {
this.n = init = n; this.init = n;
this.counter = new CountDownLatch(n);
} }
synchronized void block() throws InterruptedException { void block() throws InterruptedException {
if(--n==0) notifyAll(); // wake up everyone else this.counter.countDown();
else wait(60*1000); // if a test takes t oo long, abort. this.counter.await(60, TimeUnit.SECONDS);
} }
/** /**
...@@ -232,7 +236,7 @@ public class NodeProvisionerTest extends HudsonTestCase { ...@@ -232,7 +236,7 @@ public class NodeProvisionerTest extends HudsonTestCase {
System.out.println("Waiting for a completion"); System.out.println("Waiting for a completion");
for (Future<FreeStyleBuild> f : builds) { for (Future<FreeStyleBuild> f : builds) {
try { try {
assertBuildStatus(Result.SUCCESS, f.get(60, TimeUnit.SECONDS)); assertBuildStatus(Result.SUCCESS, f.get(90, TimeUnit.SECONDS));
} catch (TimeoutException e) { } catch (TimeoutException e) {
// time out so that the automated test won't hang forever, even when we have bugs // 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"); System.out.println("Build didn't complete in time");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册