Skip to content
Permalink
Browse files

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

Reviewed-by: herrick, asemenyuk
  • Loading branch information
Alexander Matveev
Alexander Matveev committed Dec 19, 2019
1 parent 9847d81 commit c751493f0c69ce7eeeb8b7770ef2b226af66c2d7
@@ -289,7 +289,7 @@ private File buildDMG(
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));
@@ -48,6 +48,11 @@ Executor saveOutput(boolean v) {
return this;
}

Executor setWaitBeforeOutput(boolean v) {
waitBeforeOutput = v;
return this;
}

Executor setProcessBuilder(ProcessBuilder v) {
pb = v;
return this;
@@ -88,6 +93,16 @@ int execute() throws IOException {
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 @@ int execute() throws IOException {
}

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 @@ private static String createLogMessage(ProcessBuilder pb) {

private ProcessBuilder pb;
private boolean saveOutput;
private boolean waitBeforeOutput;
private List<String> output;
private Consumer<Stream<String>> outputConsumer;
}
@@ -147,20 +147,33 @@ public static void run(String launcher, File paramFile)

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();

0 comments on commit c751493

Please sign in to comment.
You can’t perform that action at this time.