Skip to content

Commit 69cbf13

Browse files
committed
Second attempt to fix server test CI failures
Switch process redirection off and instead consume streams and copy to System.out/System.err. See gh-12689
1 parent 7498e7f commit 69cbf13

File tree

1 file changed

+28
-3
lines changed
  • spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded

1 file changed

+28
-3
lines changed

spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java

+28-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818

1919
import java.io.File;
2020
import java.io.FileReader;
21-
import java.lang.ProcessBuilder.Redirect;
21+
import java.io.IOException;
22+
import java.io.InputStream;
23+
import java.io.PrintStream;
2224
import java.util.ArrayList;
2325
import java.util.List;
2426

2527
import org.junit.rules.ExternalResource;
2628

2729
import org.springframework.util.FileCopyUtils;
30+
import org.springframework.util.StreamUtils;
2831
import org.springframework.util.StringUtils;
2932

3033
/**
@@ -76,12 +79,12 @@ private Process startApplication() throws Exception {
7679
arguments.addAll(getArguments(archive));
7780
ProcessBuilder processBuilder = new ProcessBuilder(
7881
StringUtils.toStringArray(arguments));
79-
processBuilder.redirectOutput(Redirect.INHERIT);
80-
processBuilder.redirectError(Redirect.INHERIT);
8182
if (workingDirectory != null) {
8283
processBuilder.directory(workingDirectory);
8384
}
8485
Process process = processBuilder.start();
86+
new ConsoleCopy(process.getInputStream(), System.out).start();
87+
new ConsoleCopy(process.getErrorStream(), System.err).start();
8588
this.httpPort = awaitServerPort(process, serverPortFile);
8689
return process;
8790
}
@@ -102,4 +105,26 @@ private int awaitServerPort(Process process, File serverPortFile) throws Excepti
102105
.parseInt(FileCopyUtils.copyToString(new FileReader(serverPortFile)));
103106
}
104107

108+
private static class ConsoleCopy extends Thread {
109+
110+
private final InputStream input;
111+
112+
private final PrintStream output;
113+
114+
ConsoleCopy(InputStream input, PrintStream output) {
115+
this.input = input;
116+
this.output = output;
117+
}
118+
119+
@Override
120+
public void run() {
121+
try {
122+
StreamUtils.copy(this.input, this.output);
123+
}
124+
catch (IOException ex) {
125+
}
126+
}
127+
128+
}
129+
105130
}

0 commit comments

Comments
 (0)