RFR: 8325525: Create jtreg test case for JDK-8325203

Alexey Semenyuk asemenyuk at openjdk.org
Thu Jun 20 15:48:11 UTC 2024


On Tue, 4 Jun 2024 07:13:15 GMT, Vanitha B P <duke at openjdk.org> wrote:

> Created jtreg test case for [JDK-8325203](https://bugs.openjdk.org/browse/JDK-8325203) issue.
> 
> The JpackageTest created tests that the child process started from the app launched by jpackage launcher is not automatically terminated when the the launcher is terminated.

Changes requested by asemenyuk (Reviewer).

The test builds an installer that must be installed as a part of the test. This will not work in an environment where tests are executed under a user account without restricted permissions. Building app image instead of an installer is sufficient for this test,

There are helper classes for writing jpackage tests in https://github.com/openjdk/jdk/tree/master/test/jdk/tools/jpackage/helpers/jdk/jpackage/test folder.

I'd not use a file to communicate PID of the started process between the launcher and the test. I'd use stdout instead:

public class ThirdPartyAppLauncher {
    public static void main(String[] args) throws IOException {
        Process process = new ProcessBuilder("regedit").start();
        System.out.println("RegEdit PID=" + process.pid());
    }
}


Compiling, jarring, and running jpackage that will create app image from the jar with these helpers would be as follows:

JPackageCommand.helloAppImage(TKit.TEST_SRC_ROOT.resolve("apps/ThirdPartyAppLauncher.java") + "*Hello").executeAndAssertImageCreated();


Then you run "ThirdPartyAppLauncher" class using jpackage launcher and capture its stdout:

String pidStr = new Executor().saveOutput().dumpOutput().setExecutable(cmd.appLauncherPath().toAbsolutePath()).execute(0).getFirstLineOfOutput();

// parse regedit PID
long regeditPid = Long.parseLong(pidStr.split("=", 2)[1]);

// Run your checks
...

// Kill only a specific regedit instance
Runtime.getRuntime().exec("taskkill /F /PID " + regeditPid);


You may use one of the existing jpackage tests for the reference (https://github.com/openjdk/jdk/blob/master/test/jdk/tools/jpackage/share/AppLauncherEnvTest.java is a good example)

test/jdk/tools/jpackage/windows/JpackageTest.java line 160:

> 158:      */
> 159:     private void closeThirdPartyApplication() throws Throwable {
> 160:         Runtime.getRuntime().exec("taskkill /F /IM regedit.exe");

I guess this will kill all regedit processes including those not started by the test. This doesn't seem right.

-------------

PR Review: https://git.openjdk.org/jdk/pull/19536#pullrequestreview-2130771716
PR Comment: https://git.openjdk.org/jdk/pull/19536#issuecomment-2181016935
PR Review Comment: https://git.openjdk.org/jdk/pull/19536#discussion_r1647775863


More information about the core-libs-dev mailing list