BEP: Positively identify the last message
Set an additional flag in the last BEP message to indicate the end
of the proto sequence. While the last event is implicit from the
child-relation (the sequence of protos is finished, if at least one
event is seen and all announced events have occurred in the stream),
an explicit marking of the last event simplifies processing.
Change-Id: I6554476f975dc9e52fdb27fb3221bd27f6097ed9
PiperOrigin-RevId: 161377092
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 a3b5b7e..cda02a7 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
@@ -269,7 +269,9 @@
@Test(timeout = 5000)
public void testSimpleStream() {
// Verify that a well-formed event is passed through and that completion of the
- // build clears the pending progress-update event.
+ // build clears the pending progress-update event. However, there is no guarantee
+ // on the order of the flushed events.
+ // Additionally, assert that the actual last event has the last_message flag set.
EventBusHandler handler = new EventBusHandler();
eventBus.register(handler);
@@ -295,8 +297,14 @@
List<BuildEvent> finalStream = transport.getEvents();
assertThat(finalStream).hasSize(3);
- assertThat(finalStream.get(1).getEventId()).isEqualTo(BuildEventId.buildFinished());
- assertThat(finalStream.get(2).getEventId()).isEqualTo(ProgressEvent.INITIAL_PROGRESS_UPDATE);
+ assertThat(ImmutableSet.of(finalStream.get(1).getEventId(), finalStream.get(2).getEventId()))
+ .isEqualTo(
+ ImmutableSet.of(BuildEventId.buildFinished(), ProgressEvent.INITIAL_PROGRESS_UPDATE));
+
+ // verify the "last_message" flag.
+ assertThat(transport.getEventProtos().get(0).getLastMessage()).isFalse();
+ assertThat(transport.getEventProtos().get(1).getLastMessage()).isFalse();
+ assertThat(transport.getEventProtos().get(2).getLastMessage()).isTrue();
while (!handler.transportSet.isEmpty()) {
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100));