aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/runtime
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2018-01-11 04:28:00 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-11 04:30:12 -0800
commit28221ff520ba753f8ea38dfe14fc90fff0605444 (patch)
tree27314cc3c9eaba13400ad0dfd7070548b44b1cfe /src/test/java/com/google/devtools/build/lib/runtime
parent15b77ec8314a6df0608bf027aab5bd5e06dcde07 (diff)
BuildEventStreamer: ingore noop-flush()s
The BuildEventStreamer supports a method flush() to report any pending stdout/stderr in the BEP; in particular, all internal buffers of for those streams are cleared (and the memory can be reclaimed). If there are no pending bytes in those streams, however, there is no need to generate an additional progress event to get rid of the buffered stream contents. Make flush() a no-op in this case. Change-Id: Ia8cf8733fdeaf4d1a50488736d2637862e7cb4f5 PiperOrigin-RevId: 181590982
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/runtime')
-rw-r--r--src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java30
1 files changed, 30 insertions, 0 deletions
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: