Skip to content

Bugfixes on tests and github actions runner for Windows #10196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Explicitly pass output stream in runArduino(..) test function
Previously while testing on Windows, if the process produces a lot of
output that is not consumed, the pr.Wait() call will never end
because the OS doesn't have enough buffering.
  • Loading branch information
cmaglie committed Jun 19, 2020
commit ef5d316f142b4bba7e5989b25031bf3555515456
31 changes: 16 additions & 15 deletions app/test/processing/app/CommandLineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -84,17 +86,17 @@ public static void findBuildPaths() throws Exception {
System.out.println("found arduino: " + arduinoPath);
}

private void consume(InputStream s) {
private void consume(InputStream s, OutputStream out) {
new Thread(() -> {
try {
IOUtils.copy(s, System.out);
IOUtils.copy(s, out);
} catch (IOException e) {
e.printStackTrace();
}
}).start();
}

public Process runArduino(boolean output, boolean success, File wd, String[] extraArgs) throws IOException, InterruptedException {
public Process runArduino(OutputStream output, boolean success, File wd, String[] extraArgs) throws IOException, InterruptedException {
Runtime rt = Runtime.getRuntime();

List<String> args = new ArrayList<>();
Expand All @@ -105,10 +107,8 @@ public Process runArduino(boolean output, boolean success, File wd, String[] ext
System.out.println("Running: " + String.join(" ", args));

Process pr = rt.exec(args.toArray(new String[0]), null, wd);
if (output) {
consume(pr.getInputStream());
consume(pr.getErrorStream());
}
consume(pr.getInputStream(), output);
consume(pr.getErrorStream(), System.err);
pr.waitFor();
if (success)
assertEquals(0, pr.exitValue());
Expand All @@ -118,7 +118,7 @@ public Process runArduino(boolean output, boolean success, File wd, String[] ext
@Test
public void testCommandLineBuildWithRelativePath() throws Exception {
File wd = new File(buildPath, "build/shared/examples/01.Basics/Blink/");
runArduino(true, true, wd, new String[] {
runArduino(System.out, true, wd, new String[] {
"--board", "arduino:avr:uno",
"--verify", "Blink.ino",
});
Expand All @@ -129,21 +129,21 @@ public void testCommandLinePreferencesSave() throws Exception {
File prefFile = File.createTempFile("test_pref", ".txt");
prefFile.deleteOnExit();

runArduino(true, true, null, new String[] {
runArduino(System.out, true, null, new String[] {
"--save-prefs",
"--preferences-file", prefFile.getAbsolutePath(),
"--version", // avoids starting the GUI
});

runArduino(true, true, null, new String[] {
runArduino(System.out, true, null, new String[] {
"--pref", "test_pref=xxx",
"--preferences-file", prefFile.getAbsolutePath(),
});

PreferencesMap prefs = new PreferencesMap(prefFile);
assertNull("preference should not be saved", prefs.get("test_pref"));

runArduino(true, true, null, new String[] {
runArduino(System.out, true, null, new String[] {
"--pref", "test_pref=xxx",
"--preferences-file", prefFile.getAbsolutePath(),
"--save-prefs",
Expand All @@ -155,17 +155,18 @@ public void testCommandLinePreferencesSave() throws Exception {

@Test
public void testCommandLineVersion() throws Exception {
Process pr = runArduino(false, true, null, new String[] {
ByteArrayOutputStream out = new ByteArrayOutputStream();
runArduino(out, true, null, new String[] {
"--version",
});

Assertions.assertThat(new String(IOUtils.toByteArray(pr.getInputStream())))
.matches("Arduino: \\d+\\.\\d+\\.\\d+.*\r?\n");
Assertions.assertThat(out.toString())
.matches("(?m)Arduino: \\d+\\.\\d+\\.\\d+.*\r?\n");
}

@Test
public void testCommandLineMultipleAction() throws Exception {
Process pr = runArduino(true, false, null, new String[] {
Process pr = runArduino(System.out, false, null, new String[] {
"--version",
"--verify",
});
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy