RFR: 8325525: Create jtreg test case for JDK-8325203
Vanitha B P
duke at openjdk.org
Wed Jul 3 04:17:23 UTC 2024
On Thu, 20 Jun 2024 15:45:11 GMT, Alexey Semenyuk <asemenyuk 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.
>
> 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 with 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)
Thanks for the inputs @alexeysemenyukoracle. I have addressed the review comments.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19536#issuecomment-2205063074
More information about the core-libs-dev
mailing list