8248248: [macos] EmptyFolderPackageTest.java fails EmptyFolderPackageTest-dmg-setup.scpt exited with 134 code

Reviewed-by: herrick, asemenyuk
This commit is contained in:
Alexander Matveev 2020-07-24 16:46:18 -07:00
parent 5db58348f8
commit bbddae5552
4 changed files with 44 additions and 9 deletions

View File

@ -359,7 +359,7 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
protoDMG.toAbsolutePath().toString(),
hdiUtilVerbosityFlag,
"-mountroot", imagesRoot.toAbsolutePath().toString());
IOUtils.exec(pb, false, null, true);
IOUtils.exec(pb, false, null, true, Executor.INFINITE_TIMEOUT);
Path mountedRoot = imagesRoot.resolve(APP_NAME.fetchFrom(params));
@ -392,7 +392,7 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
try {
pb = new ProcessBuilder("osascript",
getConfig_VolumeScript(params).toAbsolutePath().toString());
IOUtils.exec(pb);
IOUtils.exec(pb, 180); // Wait 3 minutes. See JDK-8248248.
} catch (IOException ex) {
Log.verbose(ex);
}

View File

@ -30,6 +30,7 @@ import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@ -55,6 +56,16 @@ final public class Executor {
return this;
}
Executor setTimeout(long v) {
timeout = v;
if (timeout != INFINITE_TIMEOUT) {
// Redirect output to file if timeout is requested, otherwise we will
// reading until process ends and timeout will never be reached.
setWriteOutputToFile(true);
}
return this;
}
Executor setProcessBuilder(ProcessBuilder v) {
pb = v;
return this;
@ -103,7 +114,7 @@ final public class Executor {
int code = 0;
if (writeOutputToFile) {
try {
code = p.waitFor();
code = waitForProcess(p);
} catch (InterruptedException ex) {
Log.verbose(ex);
throw new RuntimeException(ex);
@ -184,6 +195,21 @@ final public class Executor {
}
}
private int waitForProcess(Process p) throws InterruptedException {
if (timeout == INFINITE_TIMEOUT) {
return p.waitFor();
} else {
if (p.waitFor(timeout, TimeUnit.SECONDS)) {
return p.exitValue();
} else {
Log.verbose(String.format("Command %s timeout after %d seconds",
createLogMessage(pb), timeout));
p.destroy();
return -1;
}
}
}
static Executor of(String... cmdline) {
return new Executor().setCommandLine(cmdline);
}
@ -201,9 +227,12 @@ final public class Executor {
return sb.toString();
}
public final static int INFINITE_TIMEOUT = -1;
private ProcessBuilder pb;
private boolean saveOutput;
private boolean writeOutputToFile;
private long timeout = INFINITE_TIMEOUT;
private List<String> output;
private Consumer<Stream<String>> outputConsumer;
}

View File

@ -148,7 +148,13 @@ public class IOUtils {
public static void exec(ProcessBuilder pb)
throws IOException {
exec(pb, false, null, false);
exec(pb, false, null, false, Executor.INFINITE_TIMEOUT);
}
// timeout in seconds. -1 will be return if process timeouts.
public static void exec(ProcessBuilder pb, long timeout)
throws IOException {
exec(pb, false, null, false, timeout);
}
// See JDK-8236282
@ -158,19 +164,20 @@ public class IOUtils {
// read this file back.
public static void exec(ProcessBuilder pb, boolean writeOutputToFile)
throws IOException {
exec(pb, false, null, writeOutputToFile);
exec(pb, false, null, writeOutputToFile, Executor.INFINITE_TIMEOUT);
}
static void exec(ProcessBuilder pb, boolean testForPresenceOnly,
PrintStream consumer) throws IOException {
exec(pb, testForPresenceOnly, consumer, false);
exec(pb, testForPresenceOnly, consumer, false, Executor.INFINITE_TIMEOUT);
}
static void exec(ProcessBuilder pb, boolean testForPresenceOnly,
PrintStream consumer, boolean writeOutputToFile) throws IOException {
PrintStream consumer, boolean writeOutputToFile, long timeout)
throws IOException {
List<String> output = new ArrayList<>();
Executor exec = Executor.of(pb).setWriteOutputToFile(writeOutputToFile)
.setOutputConsumer(lines -> {
.setTimeout(timeout).setOutputConsumer(lines -> {
lines.forEach(output::add);
if (consumer != null) {
output.forEach(consumer::println);

View File

@ -928,6 +928,5 @@ jdk/jfr/event/os/TestThreadContextSwitches.java 8247776 windows-
# jdk_jpackage
tools/jpackage/share/jdk/jpackage/tests/ModulePathTest3.java#id0 8248418 generic-all
tools/jpackage/share/EmptyFolderPackageTest.java 8249201 macosx-all
############################################################################