Skip to content

Commit 1621776

Browse files
committedJun 19, 2020
test: gather all output before going on with tests
Wait for consumer thread to collect all output before returning from command line run. This patch avoid a race condition (the test output is checked before all the output is actually collected).
1 parent ea25c35 commit 1621776

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed
 

‎app/test/processing/app/CommandLineTest.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,16 @@ public static void findBuildPaths() throws Exception {
8686
System.out.println("found arduino: " + arduinoPath);
8787
}
8888

89-
private void consume(InputStream s, OutputStream out) {
90-
new Thread(() -> {
89+
private Thread consume(InputStream s, OutputStream out) {
90+
Thread t = new Thread(() -> {
9191
try {
9292
IOUtils.copy(s, out);
9393
} catch (IOException e) {
9494
e.printStackTrace();
9595
}
96-
}).start();
96+
});
97+
t.start();
98+
return t;
9799
}
98100

99101
public Process runArduino(OutputStream output, boolean success, File wd, String[] extraArgs) throws IOException, InterruptedException {
@@ -107,9 +109,11 @@ public Process runArduino(OutputStream output, boolean success, File wd, String[
107109
System.out.println("Running: " + String.join(" ", args));
108110

109111
Process pr = rt.exec(args.toArray(new String[0]), null, wd);
110-
consume(pr.getInputStream(), output);
111-
consume(pr.getErrorStream(), System.err);
112+
Thread outThread = consume(pr.getInputStream(), output);
113+
Thread errThread = consume(pr.getErrorStream(), System.err);
112114
pr.waitFor();
115+
outThread.join(5000);
116+
errThread.join(5000);
113117
if (success)
114118
assertEquals(0, pr.exitValue());
115119
return pr;

0 commit comments

Comments
 (0)
Failed to load comments.