diff options
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java | 5 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java | 30 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java index 6cb2821d28..7c54ec4600 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java @@ -19,6 +19,7 @@ import static com.google.devtools.build.lib.events.Event.of; import static com.google.devtools.build.lib.events.EventKind.PROGRESS; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Strings; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; @@ -515,6 +516,10 @@ public class BuildEventStreamer implements EventHandler { out = outErrProvider.getOut(); err = outErrProvider.getErr(); } + if (Strings.isNullOrEmpty(out) && Strings.isNullOrEmpty(err)) { + // Nothing to flush; avoid generating an unneeded progress event. + return; + } if (announcedEvents != null) { updateEvent = flushStdoutStderrEvent(out, err); } else { diff --git a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java index 541843b9fc..81b4328eaf 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java @@ -699,6 +699,36 @@ public class BuildEventStreamerTest extends FoundationTestCase { } @Test + public void testNoopFlush() throws Exception { + // Verify that the streamer ignores a flush, if neither stream produces any output. + RecordingBuildEventTransport transport = new RecordingBuildEventTransport(); + BuildEventStreamer streamer = + new BuildEventStreamer(ImmutableSet.<BuildEventTransport>of(transport), reporter); + BuildEventStreamer.OutErrProvider outErr = + Mockito.mock(BuildEventStreamer.OutErrProvider.class); + String stdoutMsg = "Some text that was written to stdout."; + String stderrMsg = "The UI text that bazel wrote to stderr."; + when(outErr.getOut()).thenReturn(stdoutMsg).thenReturn(""); + when(outErr.getErr()).thenReturn(stderrMsg).thenReturn(""); + BuildEvent startEvent = + new GenericBuildEvent( + testId("Initial"), + ImmutableSet.<BuildEventId>of(ProgressEvent.INITIAL_PROGRESS_UPDATE)); + + streamer.registerOutErrProvider(outErr); + streamer.buildEvent(startEvent); + assertThat(transport.getEvents()).hasSize(1); + streamer.flush(); // Output, so a new progress event has to be added + assertThat(transport.getEvents()).hasSize(2); + streamer.flush(); // No further output, so no additional event should be generated. + assertThat(transport.getEvents()).hasSize(2); + + assertThat(transport.getEvents().get(0)).isEqualTo(startEvent); + assertThat(transport.getEventProtos().get(1).getProgress().getStdout()).isEqualTo(stdoutMsg); + assertThat(transport.getEventProtos().get(1).getProgress().getStderr()).isEqualTo(stderrMsg); + } + + @Test public void testEarlyFlushBadInitialEvent() throws Exception { // Verify that an early flush works correctly with an unusual start event. // In this case, we expect 3 events in the stream, in that order: |