From 8fcda35317dd82d71033c9ec5a7e53932c92a024 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Fri, 6 Nov 2009 23:20:06 +0000 Subject: [PATCH] Future.cancel is asynchronous, so it can return before the process is actually killed git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@23551 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/test/java/hudson/LauncherTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/hudson/LauncherTest.java b/core/src/test/java/hudson/LauncherTest.java index 55e8acadab..3aa818fef8 100644 --- a/core/src/test/java/hudson/LauncherTest.java +++ b/core/src/test/java/hudson/LauncherTest.java @@ -31,16 +31,16 @@ import hudson.util.ProcessTree; import java.io.File; import java.io.PipedInputStream; import java.io.PipedOutputStream; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.Callable; + import junit.framework.TestCase; import org.apache.commons.io.IOUtils; import org.apache.commons.io.FileUtils; public class LauncherTest extends TestCase { - public LauncherTest(String n) { super(n); } @@ -83,6 +83,7 @@ public class LauncherTest extends TestCase { assertTrue(p.join()!=0); long end = System.currentTimeMillis(); assertTrue("join finished promptly", (end - start < 5000)); + french.call(NOOP); // this only returns after the other side of the channel has finished executing cancellation assertNull("process should be gone",ProcessTree.get().get(Integer.parseInt(FileUtils.readFileToString(tmp).trim()))); // Manual version of test: set up instance w/ one slave. Now in script console @@ -94,4 +95,9 @@ public class LauncherTest extends TestCase { // hangs and on slave machine pgrep sleep => one process; after manual kill, script returns. } + private static final hudson.remoting.Callable NOOP = new hudson.remoting.Callable() { + public Object call() throws Exception { + return null; + } + }; }