8235738: [macos] tools/jpackage tests timeout on macOS

Reviewed-by: herrick, asemenyuk
This commit is contained in:
Alexander Matveev 2019-12-19 15:20:53 -05:00
parent 9847d8161b
commit c751493f0c
3 changed files with 38 additions and 6 deletions

View File

@ -289,7 +289,7 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
protoDMG.getAbsolutePath(),
hdiUtilVerbosityFlag,
"-mountroot", imagesRoot.getAbsolutePath());
IOUtils.exec(pb);
IOUtils.exec(pb, false, null, true);
File mountedRoot = new File(imagesRoot.getAbsolutePath(),
APP_NAME.fetchFrom(params));

View File

@ -48,6 +48,11 @@ final public class Executor {
return this;
}
Executor setWaitBeforeOutput(boolean v) {
waitBeforeOutput = v;
return this;
}
Executor setProcessBuilder(ProcessBuilder v) {
pb = v;
return this;
@ -88,6 +93,16 @@ final public class Executor {
Log.verbose(String.format("Running %s", createLogMessage(pb)));
Process p = pb.start();
int code = 0;
if (waitBeforeOutput) {
try {
code = p.waitFor();
} catch (InterruptedException ex) {
Log.verbose(ex);
throw new RuntimeException(ex);
}
}
if (needProcessOutput) {
try (var br = new BufferedReader(new InputStreamReader(
p.getInputStream()))) {
@ -131,7 +146,10 @@ final public class Executor {
}
try {
return p.waitFor();
if (!waitBeforeOutput) {
code = p.waitFor();
}
return code;
} catch (InterruptedException ex) {
Log.verbose(ex);
throw new RuntimeException(ex);
@ -157,6 +175,7 @@ final public class Executor {
private ProcessBuilder pb;
private boolean saveOutput;
private boolean waitBeforeOutput;
private List<String> output;
private Consumer<Stream<String>> outputConsumer;
}

View File

@ -147,20 +147,33 @@ public class IOUtils {
public static void exec(ProcessBuilder pb)
throws IOException {
exec(pb, false, null);
exec(pb, false, null, false);
}
static void exec(ProcessBuilder pb, boolean testForPresenseOnly,
// Reading output from some processes (currently known "hdiutil attach" might hang even if process already
// exited. Only possible workaround found in "hdiutil attach" case is to wait for process to exit before
// reading output.
public static void exec(ProcessBuilder pb, boolean waitBeforeOutput)
throws IOException {
exec(pb, false, null, waitBeforeOutput);
}
static void exec(ProcessBuilder pb, boolean testForPresenceOnly,
PrintStream consumer) throws IOException {
exec(pb, testForPresenceOnly, consumer, false);
}
static void exec(ProcessBuilder pb, boolean testForPresenceOnly,
PrintStream consumer, boolean waitBeforeOutput) throws IOException {
List<String> output = new ArrayList<>();
Executor exec = Executor.of(pb).setOutputConsumer(lines -> {
Executor exec = Executor.of(pb).setWaitBeforeOutput(waitBeforeOutput).setOutputConsumer(lines -> {
lines.forEach(output::add);
if (consumer != null) {
output.forEach(consumer::println);
}
});
if (testForPresenseOnly) {
if (testForPresenceOnly) {
exec.execute();
} else {
exec.executeExpectSuccess();