Skip to content

Commit

Permalink
Enable autoFlush for JUnit printstream so we get output as the tests run
Browse files Browse the repository at this point in the history
Without autoFlush the buffer is never flushed and we get no output during the test run.

Testing Done:
Travis CI: https://travis-ci.org/pantsbuild/pants/builds/146186132

And installing the new junit-runner.jar and running java tests in the Pants repo.

In regards to the speedup in https://rbcommons.com/s/twitter/r/4101/

The tests are not as fast with the autoFlush enabled but hopefully they are fast enough?

```
$ ./pants test.junit tests/java/org/pantsbuild/tools/junit/impl/::
...
11:40:57 00:15       [run]
                     Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
                     Java HotSpot(TM) 64-Bit Server VM warning: ignoring option UseSplitVerifier; support was removed in 8.0
                     Auto-detected 8 processors, using -parallel-threads=8
                     ........................................................................................................................................................................................................................................................................................................................................................................................
                     Time: 148.382

                     OK (376 tests)
```

Bugs closed: 3698

Reviewed at https://rbcommons.com/s/twitter/r/4102/
  • Loading branch information
cheister committed Jul 21, 2016
1 parent a2fe1dc commit 0ed2684
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,9 @@ public void setNumRetries(int numRetries) {
options.numTestShards,
options.numRetries,
options.useExperimentalRunner,
// NB: Buffering yields ~factor of 100 speedups for output-heavy tests.
new PrintStream(new BufferedOutputStream(System.out)),
new PrintStream(new BufferedOutputStream(System.err)));
// NB: Buffering helps speedup output-heavy tests.
new PrintStream(new BufferedOutputStream(System.out), true),
new PrintStream(new BufferedOutputStream(System.err), true));

List<String> tests = Lists.newArrayList();
for (String test : options.tests) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public void testConsoleOutput() {
invokeConsoleRunner("MockTest4 -parallel-threads 1 -xmlreport");
Assert.assertEquals("test41 test42", TestRegistry.getCalledTests());

System.out.flush();
String output = outContent.toString();
assertThat(output, containsString("test41"));
assertThat(output, containsString("start test42"));
Expand Down

0 comments on commit 0ed2684

Please sign in to comment.