8130296: [TESTBUG] java/lang/ProcessHandle/OnExitTest - Unaccounted for children expected [0] but found [1]
authorrriggs
Wed, 08 Jul 2015 21:54:32 -0400
changeset 31537 704fd18b5be1
parent 31536 3090612af7dd
child 31538 0981099a3e54
8130296: [TESTBUG] java/lang/ProcessHandle/OnExitTest - Unaccounted for children expected [0] but found [1] Summary: Ignore extra processes that are not created by the test and cleanup any remaining child processes Reviewed-by: darcy
jdk/test/java/lang/ProcessHandle/OnExitTest.java
--- a/jdk/test/java/lang/ProcessHandle/OnExitTest.java	Wed Jul 08 23:52:15 2015 +0000
+++ b/jdk/test/java/lang/ProcessHandle/OnExitTest.java	Wed Jul 08 21:54:32 2015 -0400
@@ -27,16 +27,19 @@
 import java.time.Instant;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
+
+import jdk.testlibrary.Utils;
+
 import org.testng.annotations.Test;
 import org.testng.Assert;
 import org.testng.TestNG;
 
 /*
  * @test
+ * @build jdk.testlibrary.Utils
  * @summary Functions of Process.onExit and ProcessHandle.onExit
  * @author Roger Riggs
  */
@@ -88,6 +91,7 @@
      */
     @Test
     public static void test2() {
+        ProcessHandle procHandle = null;
         try {
             ConcurrentHashMap<ProcessHandle, ProcessHandle> processes = new ConcurrentHashMap<>();
             List<ProcessHandle> children = getChildren(ProcessHandle.current());
@@ -96,7 +100,7 @@
                     "Expected to start with zero children; " + children);
 
             JavaChild proc = JavaChild.spawnJavaChild("stdin");
-            ProcessHandle procHandle = proc.toHandle();
+            procHandle = proc.toHandle();
             printf(" spawned: %d%n", proc.getPid());
 
             proc.forEachOutputLine((s) -> {
@@ -114,7 +118,8 @@
 
             // Poll until all 9 child processes exist or the timeout is reached
             int expected = 9;
-            Instant endTimeout = Instant.now().plusSeconds(10L);
+            long timeout = Utils.adjustTimeout(10L);
+            Instant endTimeout = Instant.now().plusSeconds(timeout);
             do {
                 Thread.sleep(200L);
                 printf(" subprocess count: %d, waiting for %d%n", processes.size(), expected);
@@ -180,13 +185,12 @@
             List<ProcessHandle> children2 = getAllChildren(procHandle);
             printf(" children2: %s%n", children2.toString());
             Assert.assertEquals(children2.size(), 0, "After onExit, expected no children");
-
-            Assert.assertEquals(remaining.size(), 0, "Unaccounted for children");
-
         } catch (IOException | InterruptedException ex) {
             Assert.fail(ex.getMessage());
         } finally {
-            destroyProcessTree(ProcessHandle.current());
+            if (procHandle != null) {
+                destroyProcessTree(procHandle);
+            }
         }
     }