use of com.google.devtools.build.lib.events.EventKind in project bazel by bazelbuild.
the class ParallelBuilderTest method testProgressReporting.
@Test
public void testProgressReporting() throws Exception {
// Build three artifacts in 3 separate actions (baz depends on bar and bar
// depends on foo. Make sure progress is reported at the beginning of all
// three actions.
List<Artifact> sourceFiles = new ArrayList<>();
for (int i = 0; i < 10; i++) {
sourceFiles.add(createInputFile("file" + i));
}
Artifact foo = createDerivedArtifact("foo");
Artifact bar = createDerivedArtifact("bar");
Artifact baz = createDerivedArtifact("baz");
bar.getPath().delete();
baz.getPath().delete();
final List<String> messages = new ArrayList<>();
EventHandler handler = new EventHandler() {
@Override
public void handle(Event event) {
EventKind k = event.getKind();
if (k == EventKind.START || k == EventKind.FINISH) {
// Remove the tmpDir as this is user specific and the assert would
// fail below.
messages.add(event.getMessage().replaceFirst(TestUtils.tmpDir(), "") + " " + event.getKind());
}
}
};
reporter.addHandler(handler);
reporter.addHandler(new PrintingEventHandler(EventKind.ALL_EVENTS));
registerAction(new TestAction(TestAction.NO_EFFECT, sourceFiles, asSet(foo)));
registerAction(new TestAction(TestAction.NO_EFFECT, asSet(foo), asSet(bar)));
registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(baz)));
buildArtifacts(baz);
// Check that the percentages increase non-linearly, because foo has 10 input files
List<String> expectedMessages = Lists.newArrayList("Test foo START", "Test foo FINISH", "Test bar START", "Test bar FINISH", "Test baz START", "Test baz FINISH");
assertThat(messages).containsAllIn(expectedMessages);
// Now do an incremental rebuild of bar and baz,
// and check the incremental progress percentages.
messages.clear();
bar.getPath().delete();
baz.getPath().delete();
// This uses a new builder instance so that we refetch timestamps from
// (in-memory) file system, rather than using cached entries.
buildArtifacts(baz);
expectedMessages = Lists.newArrayList("Test bar START", "Test bar FINISH", "Test baz START", "Test baz FINISH");
assertThat(messages).containsAllIn(expectedMessages);
}
Aggregations