Skip to content

Commit ea58344

Browse files
author
Alexey Semenyuk
committed
8373887: jpackage tests may potentially deadlock
Reviewed-by: almatvee
1 parent c16ce92 commit ea58344

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/ExecutorTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,13 @@ void test() {
210210

211211
assertEquals(0, result[0].getExitCode());
212212

213-
assertEquals(expectedCapturedSystemOut(commandWithDiscardedStreams), outputCapture.outLines());
213+
// If we dump the subprocesses's output, and the command produced both STDOUT and STDERR,
214+
// then the captured STDOUT may contain interleaved command's STDOUT and STDERR,
215+
// not in sequential order (STDOUT followed by STDERR).
216+
// In this case don't check the contents of the captured command's STDOUT.
217+
if (toolProvider || outputCapture.outLines().isEmpty() || (command.stdout().isEmpty() || command.stderr().isEmpty())) {
218+
assertEquals(expectedCapturedSystemOut(commandWithDiscardedStreams), outputCapture.outLines());
219+
}
214220
assertEquals(expectedCapturedSystemErr(commandWithDiscardedStreams), outputCapture.errLines());
215221

216222
assertEquals(expectedResultStdout(commandWithDiscardedStreams), result[0].stdout().getOutput());

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Executor.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.io.OutputStream;
3333
import java.io.PrintStream;
3434
import java.io.StringReader;
35+
import java.io.UncheckedIOException;
3536
import java.io.Writer;
3637
import java.nio.file.Path;
3738
import java.util.ArrayList;
@@ -42,12 +43,15 @@
4243
import java.util.Objects;
4344
import java.util.Optional;
4445
import java.util.Set;
46+
import java.util.concurrent.CompletableFuture;
47+
import java.util.concurrent.CompletionException;
4548
import java.util.function.Supplier;
4649
import java.util.regex.Pattern;
4750
import java.util.spi.ToolProvider;
4851
import java.util.stream.Collectors;
4952
import java.util.stream.Stream;
5053
import jdk.jpackage.internal.util.function.ThrowingSupplier;
54+
import jdk.jpackage.internal.util.function.ExceptionBox;
5155

5256
public final class Executor extends CommandArguments<Executor> {
5357

@@ -465,9 +469,37 @@ private Result runExecutable() throws IOException, InterruptedException {
465469
trace("Execute " + sb.toString() + "...");
466470
Process process = builder.start();
467471

468-
final var output = combine(
469-
processProcessStream(outputStreamsControl.stdout(), process.getInputStream()),
470-
processProcessStream(outputStreamsControl.stderr(), process.getErrorStream()));
472+
var stdoutGobbler = CompletableFuture.<Optional<List<String>>>supplyAsync(() -> {
473+
try {
474+
return processProcessStream(outputStreamsControl.stdout(), process.getInputStream());
475+
} catch (IOException ex) {
476+
throw new UncheckedIOException(ex);
477+
}
478+
});
479+
480+
var stderrGobbler = CompletableFuture.<Optional<List<String>>>supplyAsync(() -> {
481+
try {
482+
return processProcessStream(outputStreamsControl.stderr(), process.getErrorStream());
483+
} catch (IOException ex) {
484+
throw new UncheckedIOException(ex);
485+
}
486+
});
487+
488+
final CommandOutput output;
489+
490+
try {
491+
output = combine(stdoutGobbler.join(), stderrGobbler.join());
492+
} catch (CompletionException ex) {
493+
var cause = ex.getCause();
494+
switch (cause) {
495+
case UncheckedIOException uioex -> {
496+
throw uioex.getCause();
497+
}
498+
default -> {
499+
throw ExceptionBox.toUnchecked(ExceptionBox.unbox(cause));
500+
}
501+
}
502+
}
471503

472504
final int exitCode = process.waitFor();
473505
trace("Done. Exit code: " + exitCode);

0 commit comments

Comments
 (0)