BEP: Add a --build_event_publish_all_actions flag to allow all actions to be published via the BEP, instead of only publishing failed actions and extra actions.
RELNOTES: Add a --build_event_publish_all_actions flag to allow all actions to be published via the BEP.
PiperOrigin-RevId: 187683799
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 3c0af6c..e2447f1 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
@@ -25,9 +25,13 @@
import com.google.common.eventbus.Subscribe;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import com.google.devtools.build.lib.actions.ActionExecutedEvent;
+import com.google.devtools.build.lib.actions.ActionExecutedEvent.ErrorTiming;
+import com.google.devtools.build.lib.actions.ActionExecutionException;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ArtifactRoot;
import com.google.devtools.build.lib.actions.EventReportingArtifacts;
+import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.ServerDirectories;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
@@ -47,6 +51,7 @@
import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent;
import com.google.devtools.build.lib.buildeventstream.PathConverter;
import com.google.devtools.build.lib.buildeventstream.ProgressEvent;
+import com.google.devtools.build.lib.buildeventstream.transports.BuildEventStreamOptions;
import com.google.devtools.build.lib.buildtool.BuildResult;
import com.google.devtools.build.lib.buildtool.buildevent.BuildCompleteEvent;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
@@ -75,6 +80,14 @@
@RunWith(JUnit4.class)
public class BuildEventStreamerTest extends FoundationTestCase {
+ private static final ActionExecutedEvent SUCCESSFUL_ACTION_EXECUTED_EVENT =
+ new ActionExecutedEvent(
+ new ActionsTestUtil.NullAction(),
+ /* exception= */ null,
+ /* stdout= */ null,
+ /* stderr= */ null,
+ ErrorTiming.NO_ERROR);
+
private static class RecordingBuildEventTransport implements BuildEventTransport {
private final List<BuildEvent> events = new ArrayList<>();
private final List<BuildEventStreamProtos.BuildEvent> eventsAsProtos = new ArrayList<>();
@@ -870,4 +883,61 @@
assertThat(ImmutableSet.of(eventsSeen.get(2).getEventId(), eventsSeen.get(3).getEventId()))
.isEqualTo(ImmutableSet.of(lateId, ProgressEvent.INITIAL_PROGRESS_UPDATE));
}
+
+ @Test
+ public void testSuccessfulActionsAreNotPublishedByDefault() {
+ EventBusHandler handler = new EventBusHandler();
+ eventBus.register(handler);
+
+ BuildEventStreamOptions options = new BuildEventStreamOptions();
+
+ RecordingBuildEventTransport transport = new RecordingBuildEventTransport();
+ BuildEventStreamer streamer =
+ new BuildEventStreamer(ImmutableSet.<BuildEventTransport>of(transport), reporter, options);
+
+ ActionExecutedEvent failedActionExecutedEvent =
+ new ActionExecutedEvent(
+ new ActionsTestUtil.NullAction(),
+ new ActionExecutionException("Exception", /* action= */ null, /* catastrophe= */ false),
+ /* stdout= */ null,
+ /* stderr= */ null,
+ ErrorTiming.BEFORE_EXECUTION);
+
+ streamer.buildEvent(SUCCESSFUL_ACTION_EXECUTED_EVENT);
+ streamer.buildEvent(failedActionExecutedEvent);
+
+ List<BuildEvent> transportedEvents = transport.getEvents();
+
+ assertThat(transportedEvents).doesNotContain(SUCCESSFUL_ACTION_EXECUTED_EVENT);
+ assertThat(transportedEvents).contains(failedActionExecutedEvent);
+ }
+
+ @Test
+ public void testSuccessfulActionsCanBePublished() {
+ EventBusHandler handler = new EventBusHandler();
+ eventBus.register(handler);
+
+ BuildEventStreamOptions options = new BuildEventStreamOptions();
+ options.publishAllActions = true;
+
+ RecordingBuildEventTransport transport = new RecordingBuildEventTransport();
+ BuildEventStreamer streamer =
+ new BuildEventStreamer(ImmutableSet.<BuildEventTransport>of(transport), reporter, options);
+
+ ActionExecutedEvent failedActionExecutedEvent =
+ new ActionExecutedEvent(
+ new ActionsTestUtil.NullAction(),
+ new ActionExecutionException("Exception", /* action= */ null, /* catastrophe= */ false),
+ /* stdout= */ null,
+ /* stderr= */ null,
+ ErrorTiming.BEFORE_EXECUTION);
+
+ streamer.buildEvent(SUCCESSFUL_ACTION_EXECUTED_EVENT);
+ streamer.buildEvent(failedActionExecutedEvent);
+
+ List<BuildEvent> transportedEvents = transport.getEvents();
+
+ assertThat(transportedEvents).contains(SUCCESSFUL_ACTION_EXECUTED_EVENT);
+ assertThat(transportedEvents).contains(failedActionExecutedEvent);
+ }
}