8150346: java/lang/ProcessHandle/InfoTest.java failed - startTime after process spawn completed
Reviewed-by: redestad, martin
--- a/jdk/test/java/lang/ProcessHandle/Basic.java Wed Jul 05 21:24:14 2017 +0200
+++ b/jdk/test/java/lang/ProcessHandle/Basic.java Mon Feb 29 18:00:40 2016 -0500
@@ -37,7 +37,7 @@
/*
* @test
* @library /test/lib/share/classes
- * @run testng InfoTest
+ * @run testng Basic
* @summary Basic tests for ProcessHandler
* @author Roger Riggs
*/
--- a/jdk/test/java/lang/ProcessHandle/InfoTest.java Wed Jul 05 21:24:14 2017 +0200
+++ b/jdk/test/java/lang/ProcessHandle/InfoTest.java Mon Feb 29 18:00:40 2016 -0500
@@ -114,9 +114,13 @@
long cpuLoopTime = 100; // 100 ms
String[] extraArgs = {"pid", "parent", "stdin"};
JavaChild p1 = JavaChild.spawnJavaChild((Object[])extraArgs);
- Instant afterStart = Instant.now();
+ Instant afterStart = null;
try (BufferedReader lines = p1.outputReader()) {
+ // Read the args line to know the subprocess has started
+ lines.readLine();
+ afterStart = Instant.now();
+
Duration lastCpu = Duration.ofMillis(0L);
for (int j = 0; j < 10; j++) {
@@ -126,8 +130,7 @@
// Read cputime from child
Duration childCpuTime = null;
// Read lines from the child until the result from cputime is returned
- String s;
- while ((s = lines.readLine()) != null) {
+ for (String s; (s = lines.readLine()) != null;) {
String[] split = s.trim().split(" ");
if (split.length == 3 && split[1].equals("cputime")) {
long nanos = Long.valueOf(split[2]);