aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar ruperts <ruperts@google.com>2018-03-02 16:10:43 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-02 16:12:27 -0800
commit76de73b979219fe2697aa9dc8f354020e1905d81 (patch)
tree88e765f3ef604d5bdd64c5a022e825dcc7f080d5 /src/test
parenta6679aead65603162d57ee5d868ab06fed369fab (diff)
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
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/BUILD1
-rw-r--r--src/test/java/com/google/devtools/build/lib/buildeventservice/BUILD2
-rw-r--r--src/test/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModuleTest.java121
-rw-r--r--src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java70
4 files changed, 128 insertions, 66 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD
index 831dbb37dd..c3d1238a85 100644
--- a/src/test/java/com/google/devtools/build/lib/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/BUILD
@@ -1173,6 +1173,7 @@ java_test(
"//src/main/protobuf:command_line_java_proto",
"//src/main/protobuf:invocation_policy_java_proto",
"//src/main/protobuf:test_status_java_proto",
+ "//src/test/java/com/google/devtools/build/lib:actions_testutil",
"//src/test/java/com/google/devtools/common/options:testutils",
"//third_party:mockito",
],
diff --git a/src/test/java/com/google/devtools/build/lib/buildeventservice/BUILD b/src/test/java/com/google/devtools/build/lib/buildeventservice/BUILD
index 44af15ac93..99da75dd66 100644
--- a/src/test/java/com/google/devtools/build/lib/buildeventservice/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/buildeventservice/BUILD
@@ -18,6 +18,7 @@ java_test(
deps = [
"//src/main/java/com/google/devtools/build/lib:events",
"//src/main/java/com/google/devtools/build/lib:runtime",
+ "//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/authandtls",
"//src/main/java/com/google/devtools/build/lib/buildeventservice",
"//src/main/java/com/google/devtools/build/lib/buildeventstream",
@@ -25,6 +26,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/clock",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/common/options",
+ "//src/test/java/com/google/devtools/build/lib:actions_testutil",
"//src/test/java/com/google/devtools/build/lib:testutil",
"//third_party:guava",
"//third_party:junit4",
diff --git a/src/test/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModuleTest.java b/src/test/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModuleTest.java
index e3444b1f74..4a297272cc 100644
--- a/src/test/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModuleTest.java
+++ b/src/test/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModuleTest.java
@@ -22,6 +22,9 @@ import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.eventbus.EventBus;
+import com.google.devtools.build.lib.actions.ActionExecutedEvent;
+import com.google.devtools.build.lib.actions.ActionExecutedEvent.ErrorTiming;
+import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.authandtls.AuthAndTLSOptions;
import com.google.devtools.build.lib.buildeventstream.PathConverter;
import com.google.devtools.build.lib.buildeventstream.transports.BinaryFormatFileTransport;
@@ -54,6 +57,14 @@ import org.mockito.MockitoAnnotations;
@RunWith(JUnit4.class)
public class BazelBuildEventServiceModuleTest {
+ private static final ActionExecutedEvent SUCCESSFUL_ACTION_EXECUTED_EVENT =
+ new ActionExecutedEvent(
+ new ActionsTestUtil.NullAction(),
+ /* exception= */ null,
+ /* stdout= */ null,
+ /* stderr= */ null,
+ ErrorTiming.NO_ERROR);
+
private static final Function<Object, Class<?>> GET_CLASS =
new Function<Object, Class<?>>() {
@Override
@@ -124,22 +135,26 @@ public class BazelBuildEventServiceModuleTest {
assertThat(options.getBuildEventJsonFile()).isEqualTo("/tmp/foo.json");
}
+ private BuildEventStreamer createBuildEventStreamerForCommand(
+ BazelBuildEventServiceModule module, String commandName) {
+ return module.tryCreateStreamer(
+ optionsProvider,
+ commandLineReporter,
+ moduleEnvironment,
+ clock,
+ PATH_CONVERTER,
+ reporter,
+ /* buildRequestId= */ "foo",
+ /* invocationId= */ "bar",
+ commandName);
+ }
+
@Test
public void testCreatesStreamerForTextFormatFileTransport() throws Exception {
when(bepOptions.getBuildEventTextFile()).thenReturn(tmp.newFile().getAbsolutePath());
BazelBuildEventServiceModule module = new BazelBuildEventServiceModule();
- BuildEventStreamer buildEventStreamer =
- module.tryCreateStreamer(
- optionsProvider,
- commandLineReporter,
- moduleEnvironment,
- clock,
- PATH_CONVERTER,
- reporter,
- "foo",
- "bar",
- "build");
+ BuildEventStreamer buildEventStreamer = createBuildEventStreamerForCommand(module, "build");
assertThat(buildEventStreamer).isNotNull();
verifyNoMoreInteractions(moduleEnvironment);
assertThat(FluentIterable.from(buildEventStreamer.getTransports()).transform(GET_CLASS))
@@ -151,17 +166,7 @@ public class BazelBuildEventServiceModuleTest {
when(bepOptions.getBuildEventBinaryFile()).thenReturn(tmp.newFile().getAbsolutePath());
BazelBuildEventServiceModule module = new BazelBuildEventServiceModule();
- BuildEventStreamer buildEventStreamer =
- module.tryCreateStreamer(
- optionsProvider,
- commandLineReporter,
- moduleEnvironment,
- clock,
- PATH_CONVERTER,
- reporter,
- "foo",
- "bar",
- "test");
+ BuildEventStreamer buildEventStreamer = createBuildEventStreamerForCommand(module, "test");
assertThat(buildEventStreamer).isNotNull();
verifyNoMoreInteractions(moduleEnvironment);
assertThat(FluentIterable.from(buildEventStreamer.getTransports()).transform(GET_CLASS))
@@ -173,17 +178,7 @@ public class BazelBuildEventServiceModuleTest {
when(bepOptions.getBuildEventJsonFile()).thenReturn(tmp.newFile().getAbsolutePath());
BazelBuildEventServiceModule module = new BazelBuildEventServiceModule();
- BuildEventStreamer buildEventStreamer =
- module.tryCreateStreamer(
- optionsProvider,
- commandLineReporter,
- moduleEnvironment,
- clock,
- PATH_CONVERTER,
- reporter,
- "foo",
- "bar",
- "fetch");
+ BuildEventStreamer buildEventStreamer = createBuildEventStreamerForCommand(module, "fetch");
assertThat(buildEventStreamer).isNotNull();
verifyNoMoreInteractions(moduleEnvironment);
assertThat(FluentIterable.from(buildEventStreamer.getTransports()).transform(GET_CLASS))
@@ -195,17 +190,7 @@ public class BazelBuildEventServiceModuleTest {
besOptions.besBackend = "does.not.exist:1234";
BazelBuildEventServiceModule module = new BazelBuildEventServiceModule();
- BuildEventStreamer buildEventStreamer =
- module.tryCreateStreamer(
- optionsProvider,
- commandLineReporter,
- moduleEnvironment,
- clock,
- PATH_CONVERTER,
- reporter,
- "foo",
- "bar",
- "build");
+ BuildEventStreamer buildEventStreamer = createBuildEventStreamerForCommand(module, "build");
assertThat(buildEventStreamer).isNotNull();
}
@@ -217,17 +202,7 @@ public class BazelBuildEventServiceModuleTest {
besOptions.besBackend = "does.not.exist:1234";
BazelBuildEventServiceModule module = new BazelBuildEventServiceModule();
- BuildEventStreamer buildEventStreamer =
- module.tryCreateStreamer(
- optionsProvider,
- commandLineReporter,
- moduleEnvironment,
- clock,
- PATH_CONVERTER,
- reporter,
- "foo",
- "bar",
- "test");
+ BuildEventStreamer buildEventStreamer = createBuildEventStreamerForCommand(module, "test");
assertThat(buildEventStreamer).isNotNull();
verifyNoMoreInteractions(moduleEnvironment);
assertThat(FluentIterable.from(buildEventStreamer.getTransports()).transform(GET_CLASS))
@@ -238,17 +213,7 @@ public class BazelBuildEventServiceModuleTest {
@Test
public void testDoesNotCreatesStreamerWithoutTransports() throws Exception {
BazelBuildEventServiceModule module = new BazelBuildEventServiceModule();
- BuildEventStreamer buildEventStreamer =
- module.tryCreateStreamer(
- optionsProvider,
- commandLineReporter,
- moduleEnvironment,
- clock,
- PATH_CONVERTER,
- reporter,
- "foo",
- "bar",
- "fetch");
+ BuildEventStreamer buildEventStreamer = createBuildEventStreamerForCommand(module, "fetch");
assertThat(buildEventStreamer).isNull();
}
@@ -259,4 +224,28 @@ public class BazelBuildEventServiceModuleTest {
assertThat(module.keywords(besOptions))
.containsExactly("user_keyword=keyword0", "user_keyword=keyword1");
}
+
+ @Test
+ public void testSuccessfulActionsAreNotPublishedByDefault() throws Exception {
+ when(bepOptions.getBuildEventTextFile()).thenReturn(tmp.newFile().getAbsolutePath());
+ BazelBuildEventServiceModule module = new BazelBuildEventServiceModule();
+ BuildEventStreamer buildEventStreamer = createBuildEventStreamerForCommand(module, "build");
+ assertThat(buildEventStreamer).isNotNull();
+
+ assertThat(buildEventStreamer.shouldIgnoreBuildEvent(SUCCESSFUL_ACTION_EXECUTED_EVENT))
+ .isTrue();
+ }
+
+ @Test
+ public void testSuccessfulActionsArePublishedWhenOptionIsSet() throws Exception {
+ bepOptions.publishAllActions = true;
+
+ when(bepOptions.getBuildEventTextFile()).thenReturn(tmp.newFile().getAbsolutePath());
+ BazelBuildEventServiceModule module = new BazelBuildEventServiceModule();
+ BuildEventStreamer buildEventStreamer = createBuildEventStreamerForCommand(module, "build");
+ assertThat(buildEventStreamer).isNotNull();
+
+ assertThat(buildEventStreamer.shouldIgnoreBuildEvent(SUCCESSFUL_ACTION_EXECUTED_EVENT))
+ .isFalse();
+ }
}
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 3c0af6c31c..e2447f10ca 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.collect.ImmutableSet;
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.BuildEventWithOrderConstra
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 @@ import org.mockito.MockitoAnnotations;
@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 @@ public class BuildEventStreamerTest extends FoundationTestCase {
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);
+ }
}