Skip to content

Commit

Permalink
Merge pull request #11199 from pshipton/timeout
Browse files Browse the repository at this point in the history
Fix getUnixPID() for jdk11+ and stop waiting for tests after 10 min
  • Loading branch information
llxia authored Nov 17, 2020
2 parents 547bb8e + 0662412 commit 4e25e83
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions test/functional/cmdline_options_tester/src/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.PrintWriter;
import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -73,6 +74,7 @@ class Test {

static String archName = System.getProperty("os.arch");
static boolean isRiscv = archName.toLowerCase().contains("riscv");
static boolean isJava8 = System.getProperty("java.specification.version").equals("1.8");

/**
* Create a new test case with the given id.
Expand Down Expand Up @@ -224,7 +226,10 @@ public boolean run(long defaultTimeout) {
TestSuite.printErrorMessage("stderr timed out");
}

proc.waitFor();
// Wait an additional 10 min after the regular timeout for the process to finish.
// It should finish because the ProcessKiller terminates it, but if it doesn't
// then don't wait forever.
proc.waitFor(_timeout + (10 * 60 * 1000), TimeUnit.MILLISECONDS);

testTimer.stop();
timer = testTimer.getTimeSpent();
Expand Down Expand Up @@ -411,14 +416,24 @@ public void dumpVerboseOutput(boolean result) {
}

public static int getUnixPID(Process process) throws Exception {
Class<?> cl = process.getClass();
if (!cl.getName().equals("java.lang.UNIXProcess") || isRiscv) {
if (isRiscv) {
return 0;
}
Field field = cl.getDeclaredField("pid");
field.setAccessible(true);
Object pidObject = field.get(process);
return ((Integer) pidObject).intValue();
if (isJava8) {
Class<?> cl = process.getClass();
if (!cl.getName().equals("java.lang.UNIXProcess")) {
return 0;
}
Field field = cl.getDeclaredField("pid");
field.setAccessible(true);
Object pidObject = field.get(process);
return ((Integer) pidObject).intValue();
} else {
// if not Java 8 then it must be Java 11 or later
Method pidMethod = Process.class.getMethod("pid");
Long pid = (Long)pidMethod.invoke(process);
return pid.intValue();
}
}

private final class StreamMatcher extends Thread {
Expand Down

0 comments on commit 4e25e83

Please sign in to comment.