aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java9
-rw-r--r--src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java25
2 files changed, 28 insertions, 6 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 c0c50958b5..a79297d396 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
@@ -43,8 +43,8 @@ import java.util.logging.Logger;
public class BuildEventStreamer implements EventHandler {
private final Collection<BuildEventTransport> transports;
private Set<BuildEventId> announcedEvents;
- private Set<BuildEventId> postedEvents;
- private final Multimap<BuildEventId, BuildEvent> pendingEvents;
+ private final Set<BuildEventId> postedEvents = new HashSet<>();
+ private final Multimap<BuildEventId, BuildEvent> pendingEvents = HashMultimap.create();
private int progressCount;
private AbortReason abortReason = AbortReason.UNKNOWN;
private static final Logger log = Logger.getLogger(BuildEventStreamer.class.getName());
@@ -52,9 +52,7 @@ public class BuildEventStreamer implements EventHandler {
public BuildEventStreamer(Collection<BuildEventTransport> transports) {
this.transports = transports;
this.announcedEvents = null;
- this.postedEvents = null;
this.progressCount = 0;
- this.pendingEvents = HashMultimap.create();
}
/**
@@ -71,7 +69,6 @@ public class BuildEventStreamer implements EventHandler {
synchronized (this) {
if (announcedEvents == null) {
announcedEvents = new HashSet<>();
- postedEvents = new HashSet<>();
if (!event.getChildrenEvents().contains(ProgressEvent.INITIAL_PROGRESS_UPDATE)) {
linkEvent = ProgressEvent.progressChainIn(progressCount, event.getEventId());
progressCount++;
@@ -85,8 +82,8 @@ public class BuildEventStreamer implements EventHandler {
announcedEvents.addAll(linkEvent.getChildrenEvents());
postedEvents.add(linkEvent.getEventId());
}
- postedEvents.add(id);
}
+ postedEvents.add(id);
announcedEvents.addAll(event.getChildrenEvents());
}
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 433f9fb4d8..5a4e444bfe 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
@@ -297,4 +297,29 @@ public class BuildEventStreamerTest {
assertEquals(rootCauseId, allEventsSeen.get(3).getEventId());
assertEquals(failedTarget.getEventId(), allEventsSeen.get(4).getEventId());
}
+
+ @Test
+ public void testVeryFirstEventNeedsToWait() {
+ // Verify that we can handle an first event waiting for another event.
+ RecordingBuildEventTransport transport = new RecordingBuildEventTransport();
+ BuildEventStreamer streamer =
+ new BuildEventStreamer(ImmutableSet.<BuildEventTransport>of(transport));
+
+ BuildEventId initialId = testId("Initial");
+ BuildEventId waitId = testId("Waiting for initial event");
+ BuildEvent startEvent =
+ new GenericBuildEvent(
+ initialId,
+ ImmutableSet.<BuildEventId>of(ProgressEvent.INITIAL_PROGRESS_UPDATE, waitId));
+ BuildEvent waitingForStart =
+ new GenericOrderEvent(waitId, ImmutableSet.<BuildEventId>of(), ImmutableSet.of(initialId));
+
+ streamer.buildEvent(waitingForStart);
+ streamer.buildEvent(startEvent);
+
+ List<BuildEvent> allEventsSeen = transport.getEvents();
+ assertThat(allEventsSeen).hasSize(2);
+ assertEquals(startEvent.getEventId(), allEventsSeen.get(0).getEventId());
+ assertEquals(waitingForStart.getEventId(), allEventsSeen.get(1).getEventId());
+ }
}