8336315: tools/jpackage/windows/WinChildProcessTest.java Failed: Check is calculator process is alive

Reviewed-by: asemenyuk, almatvee
This commit is contained in:
Vanitha B P 2024-07-30 15:04:57 +00:00 committed by Alexey Semenyuk
parent 1cb27f7e23
commit 2c9fd9016f
2 changed files with 19 additions and 15 deletions

View File

@ -26,12 +26,17 @@ import java.io.IOException;
import java.nio.file.Path;
public class ChildProcessAppLauncher {
public static void main(String[] args) throws IOException {
String calcPath = Path.of(System.getenv("SystemRoot"), "system32", "calc.exe").toString();
ProcessBuilder processBuilder = new ProcessBuilder(calcPath);
public static void main(String[] args) throws IOException, InterruptedException {
if (args.length == 1 && "noexit".equals(args[0])) {
var lock = new Object();
synchronized (lock) {
lock.wait();
}
} else {
var childPath = System.getProperty("jpackage.app-path"); // get the path to the current jpackage app launcher
ProcessBuilder processBuilder = new ProcessBuilder(childPath, "noexit"); //ChildProcessAppLauncher acts as third party app
Process process = processBuilder.start();
System.out.println("Calc id=" + process.pid());
System.exit(0);
System.out.println("Child id=" + process.pid());
}
}
}

View File

@ -53,7 +53,7 @@ public class WinChildProcessTest {
@Test
public static void test() throws Throwable {
long calcPid = 0;
long childPid = 0;
try {
JPackageCommand cmd = JPackageCommand
.helloAppImage(TEST_APP_JAVA + "*Hello");
@ -68,21 +68,20 @@ public class WinChildProcessTest {
.execute(0).getOutput();
String pidStr = output.get(0);
// parse calculator PID
calcPid = Long.parseLong(pidStr.split("=", 2)[1]);
// parse child PID
childPid = Long.parseLong(pidStr.split("=", 2)[1]);
// Check whether the termination of third party application launcher
// also terminating the launched third party application
// If third party application is not terminated the test is
// successful else failure
Optional<ProcessHandle> processHandle = ProcessHandle.of(calcPid);
Optional<ProcessHandle> processHandle = ProcessHandle.of(childPid);
boolean isAlive = processHandle.isPresent()
&& processHandle.get().isAlive();
System.out.println("Is Alive " + isAlive);
TKit.assertTrue(isAlive, "Check is calculator process is alive");
TKit.assertTrue(isAlive, "Check is child process is alive");
} finally {
// Kill only a specific calculator instance
Runtime.getRuntime().exec("taskkill /F /PID " + calcPid);
// Kill only a specific child instance
Runtime.getRuntime().exec("taskkill /F /PID " + childPid);
}
}
}
}