use of com.google.devtools.build.lib.util.io.LoggingTerminalWriter in project bazel by bazelbuild.
the class ExperimentalStateTrackerTest method testLoadingActivity.
@Test
public void testLoadingActivity() throws IOException {
// During loading phase, state and activity, as reported by the PackageProgressReceiver,
// should be visible in the progress bar.
String state = "42 packages loaded";
String activity = "currently loading //src/foo/bar and 17 more";
PackageProgressReceiver progress = Mockito.mock(PackageProgressReceiver.class);
when(progress.progressState()).thenReturn(new Pair<String, String>(state, activity));
ManualClock clock = new ManualClock();
ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
stateTracker.loadingStarted(new LoadingPhaseStartedEvent(progress));
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter);
String output = terminalWriter.getTranscript();
assertTrue("Output should indicate that we are in the loading phase, but was:\n" + output, output.contains("Loading"));
assertTrue("Output should contain loading state '" + state + "', but was:\n" + output, output.contains(state));
assertTrue("Output should contain loading state '" + activity + "', but was:\n" + output, output.contains(activity));
}
use of com.google.devtools.build.lib.util.io.LoggingTerminalWriter in project bazel by bazelbuild.
the class ExperimentalStateTrackerTest method testAggregation.
@Test
public void testAggregation() throws Exception {
// Assert that actions for the same test are aggregated so that an action afterwards
// is still shown.
ManualClock clock = new ManualClock();
clock.advanceMillis(TimeUnit.SECONDS.toMillis(1234));
ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock, 80);
Label labelFooTest = Label.parseAbsolute("//foo/bar:footest");
ConfiguredTarget targetFooTest = Mockito.mock(ConfiguredTarget.class);
when(targetFooTest.getLabel()).thenReturn(labelFooTest);
ActionOwner fooOwner = ActionOwner.create(labelFooTest, ImmutableList.<AspectDescriptor>of(), null, null, null, "abcdef", null);
Label labelBarTest = Label.parseAbsolute("//baz:bartest");
ConfiguredTarget targetBarTest = Mockito.mock(ConfiguredTarget.class);
when(targetBarTest.getLabel()).thenReturn(labelBarTest);
TestFilteringCompleteEvent filteringComplete = Mockito.mock(TestFilteringCompleteEvent.class);
when(filteringComplete.getTestTargets()).thenReturn(ImmutableSet.of(targetFooTest, targetBarTest));
ActionOwner barOwner = ActionOwner.create(labelBarTest, ImmutableList.<AspectDescriptor>of(), null, null, null, "fedcba", null);
stateTracker.testFilteringComplete(filteringComplete);
// First produce 10 actions for footest...
for (int i = 0; i < 10; i++) {
clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
Action action = mockAction("Testing foo, shard " + i, "testlog_foo_" + i);
when(action.getOwner()).thenReturn(fooOwner);
stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
}
// ...then produce 10 actions for bartest...
for (int i = 0; i < 10; i++) {
clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
Action action = mockAction("Testing bar, shard " + i, "testlog_bar_" + i);
when(action.getOwner()).thenReturn(barOwner);
stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
}
// ...and finally a completely unrelated action
clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
stateTracker.actionStarted(new ActionStartedEvent(mockAction("Other action", "other/action"), clock.nanoTime()));
clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter);
String output = terminalWriter.getTranscript();
assertTrue("Progress bar should contain ':footest', but was:\n" + output, output.contains(":footest"));
assertTrue("Progress bar should contain ':bartest', but was:\n" + output, output.contains(":bartest"));
assertTrue("Progress bar should contain 'Other action', but was:\n" + output, output.contains("Other action"));
}
use of com.google.devtools.build.lib.util.io.LoggingTerminalWriter in project bazel by bazelbuild.
the class ExperimentalStateTrackerTest method testOldestActionVisible.
@Test
public void testOldestActionVisible() throws IOException {
// The earliest-started action is always visible somehow in the progress bar
// and its short version.
String messageOld = "Running the first-started action";
ManualClock clock = new ManualClock();
clock.advanceMillis(120000);
ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
stateTracker.actionStarted(new ActionStartedEvent(mockAction(messageOld, "bar/foo"), 123456789));
for (int i = 0; i < 30; i++) {
stateTracker.actionStarted(new ActionStartedEvent(mockAction("Other action " + i, "some/other/actions/number" + i), 123456790 + i));
}
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter);
String output = terminalWriter.getTranscript();
assertTrue("Longest running action '" + messageOld + "' should be visible in output: " + output, output.contains(messageOld));
terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/
true);
output = terminalWriter.getTranscript();
assertTrue("Longest running action '" + messageOld + "' should be visible in short output: " + output, output.contains(messageOld));
}
use of com.google.devtools.build.lib.util.io.LoggingTerminalWriter in project bazel by bazelbuild.
the class ExperimentalStateTrackerTest method testActionStrategyVisible.
@Test
public void testActionStrategyVisible() throws Exception {
// verify that, if a strategy was reported for a shown action, it is visible
// in the progress bar.
String strategy = "verySpecialStrategy";
String primaryOutput = "some/path/to/a/file";
ManualClock clock = new ManualClock();
Path path = outputBase.getRelative(new PathFragment(primaryOutput));
Artifact artifact = new Artifact(path, Root.asSourceRoot(path));
ActionExecutionMetadata actionMetadata = Mockito.mock(ActionExecutionMetadata.class);
when(actionMetadata.getOwner()).thenReturn(Mockito.mock(ActionOwner.class));
when(actionMetadata.getPrimaryOutput()).thenReturn(artifact);
ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
stateTracker.actionStarted(new ActionStartedEvent(mockAction("Some random action", primaryOutput), clock.nanoTime()));
stateTracker.actionStatusMessage(ActionStatusMessage.runningStrategy(actionMetadata, strategy));
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter);
String output = terminalWriter.getTranscript();
assertTrue("Output should mention strategy '" + strategy + "', but was: " + output, output.contains(strategy));
}
use of com.google.devtools.build.lib.util.io.LoggingTerminalWriter in project bazel by bazelbuild.
the class ExperimentalStateTrackerTest method testDownloadShown.
@Test
public void testDownloadShown() throws Exception {
// Verify that, whenever a single download is running in loading face, it is shown in the status
// bar.
ManualClock clock = new ManualClock();
clock.advanceMillis(TimeUnit.SECONDS.toMillis(1234));
ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock, 80);
URL url = new URL("http://example.org/first/dep");
stateTracker.buildStarted(null);
stateTracker.downloadProgress(new DownloadProgressEvent(url));
clock.advanceMillis(TimeUnit.SECONDS.toMillis(6));
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter);
String output = terminalWriter.getTranscript();
assertTrue("Progress bar should contain '" + url.toString() + "', but was:\n" + output, output.contains(url.toString()));
assertTrue("Progress bar should contain '6s', but was:\n" + output, output.contains("6s"));
// Progress on the pending download should be reported appropriately
clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
stateTracker.downloadProgress(new DownloadProgressEvent(url, 256));
terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter);
output = terminalWriter.getTranscript();
assertTrue("Progress bar should contain '" + url.toString() + "', but was:\n" + output, output.contains(url.toString()));
assertTrue("Progress bar should contain '7s', but was:\n" + output, output.contains("7s"));
assertTrue("Progress bar should contain '256', but was:\n" + output, output.contains("256"));
// After finishing the download, it should no longer be reported.
clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
stateTracker.downloadProgress(new DownloadProgressEvent(url, 256, true));
terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter);
output = terminalWriter.getTranscript();
assertFalse("Progress bar should not contain url, but was:\n" + output, output.contains("example.org"));
}
Aggregations