8333569: jpackage tests must run app launchers with retries on Linux only

Backport-of: ce312b3ecbbacaf23f4b2893898ce8de8cd53daa
This commit is contained in:
Goetz Lindenmaier 2025-11-18 08:52:17 +00:00
parent cb258e5fba
commit 2635b9deec
3 changed files with 24 additions and 27 deletions

View File

@ -351,16 +351,6 @@ public final class HelloApp {
this.outputFilePath = TKit.workDir().resolve(OUTPUT_FILENAME);
this.params = new HashMap<>();
this.defaultLauncherArgs = new ArrayList<>();
if (TKit.isWindows()) {
// When running app launchers on Windows, clear users environment (JDK-8254920)
removePath(true);
}
}
public AppOutputVerifier removePath(boolean v) {
removePath = v;
return this;
}
public AppOutputVerifier saveOutput(boolean v) {
@ -442,10 +432,7 @@ public final class HelloApp {
if (launcherNoExit) {
return getExecutor(args).executeWithoutExitCodeCheck();
} else {
final int attempts = 3;
final int waitBetweenAttemptsSeconds = 5;
return getExecutor(args).executeAndRepeatUntilExitCode(expectedExitCode, attempts,
waitBetweenAttemptsSeconds);
return HelloApp.execute(expectedExitCode, getExecutor(args));
}
}
@ -475,7 +462,6 @@ public final class HelloApp {
}
private boolean launcherNoExit;
private boolean removePath;
private boolean saveOutput;
private final Path launcherPath;
private Path outputFilePath;
@ -488,7 +474,22 @@ public final class HelloApp {
return new AppOutputVerifier(helloAppLauncher);
}
public static Executor configureEnvironment(Executor executor) {
public static Executor.Result configureAndExecute(int expectedExitCode, Executor executor) {
return execute(expectedExitCode, configureEnvironment(executor));
}
private static Executor.Result execute(int expectedExitCode, Executor executor) {
if (TKit.isLinux()) {
final int attempts = 3;
final int waitBetweenAttemptsSeconds = 5;
return executor.executeAndRepeatUntilExitCode(expectedExitCode, attempts,
waitBetweenAttemptsSeconds);
} else {
return executor.execute(expectedExitCode);
}
}
private static Executor configureEnvironment(Executor executor) {
if (CLEAR_JAVA_ENV_VARS) {
executor.removeEnvVar("JAVA_TOOL_OPTIONS");
executor.removeEnvVar("_JAVA_OPTIONS");

View File

@ -30,7 +30,7 @@ import java.util.stream.Stream;
import jdk.jpackage.test.JPackageCommand;
import jdk.jpackage.test.Annotations.Test;
import jdk.jpackage.test.Executor;
import static jdk.jpackage.test.HelloApp.configureEnvironment;
import static jdk.jpackage.test.HelloApp.configureAndExecute;
import jdk.jpackage.test.TKit;
/**
@ -62,16 +62,12 @@ public class AppLauncherEnvTest {
final String envVarName = envVarName();
final int attempts = 3;
final int waitBetweenAttemptsSeconds = 5;
List<String> output = configureEnvironment(new Executor())
List<String> output = configureAndExecute(0, new Executor()
.saveOutput()
.setExecutable(cmd.appLauncherPath().toAbsolutePath())
.addArguments("--print-env-var=" + envVarName)
.addArguments("--print-sys-prop=" + testAddDirProp)
.addArguments("--print-sys-prop=" + "java.library.path")
.executeAndRepeatUntilExitCode(0, attempts,
waitBetweenAttemptsSeconds).getOutput();
.addArguments("--print-sys-prop=" + "java.library.path")).getOutput();
BiFunction<Integer, String, String> getValue = (idx, name) -> {
return output.get(idx).substring((name + "=").length());

View File

@ -40,7 +40,7 @@ import java.util.Optional;
import java.nio.file.Path;
import jdk.jpackage.test.JPackageCommand;
import static jdk.jpackage.test.HelloApp.configureEnvironment;
import static jdk.jpackage.test.HelloApp.configureAndExecute;
import jdk.jpackage.test.Annotations.Test;
import jdk.jpackage.test.Executor;
import jdk.jpackage.test.TKit;
@ -63,9 +63,9 @@ public class WinChildProcessTest {
// Start the third party application launcher and dump and save the
// output of the application
List<String> output = configureEnvironment(new Executor()).saveOutput().dumpOutput()
.setExecutable(cmd.appLauncherPath().toAbsolutePath())
.execute(0).getOutput();
List<String> output = configureAndExecute(0, new Executor().saveOutput().dumpOutput()
.setExecutable(cmd.appLauncherPath().toAbsolutePath()))
.getOutput();
String pidStr = output.get(0);
// parse child PID