use of com.google.devtools.build.lib.util.io.LoggingTerminalWriter in project bazel by bazelbuild.
the class ExperimentalStateTrackerTest method testCountVisible.
@Test
public void testCountVisible() throws Exception {
// The test count should be visible in the status bar, as well as the short status bar
ManualClock clock = new ManualClock();
ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
TestFilteringCompleteEvent filteringComplete = Mockito.mock(TestFilteringCompleteEvent.class);
Label labelA = Label.parseAbsolute("//foo/bar:baz");
ConfiguredTarget targetA = Mockito.mock(ConfiguredTarget.class);
when(targetA.getLabel()).thenReturn(labelA);
ConfiguredTarget targetB = Mockito.mock(ConfiguredTarget.class);
when(filteringComplete.getTestTargets()).thenReturn(ImmutableSet.of(targetA, targetB));
TestSummary testSummary = Mockito.mock(TestSummary.class);
when(testSummary.getTarget()).thenReturn(targetA);
stateTracker.testFilteringComplete(filteringComplete);
stateTracker.testSummary(testSummary);
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter);
String output = terminalWriter.getTranscript();
assertTrue("Test count should be visible in output: " + output, output.contains(" 1 / 2 tests"));
terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/
true);
output = terminalWriter.getTranscript();
assertTrue("Test count should be visible in short output: " + output, output.contains(" 1 / 2 tests"));
}
use of com.google.devtools.build.lib.util.io.LoggingTerminalWriter in project bazel by bazelbuild.
the class ExperimentalStateTrackerTest method testSampleSize.
@Test
public void testSampleSize() throws IOException {
// Verify that the number of actions shown in the progress bar can be set as sample size.
ManualClock clock = new ManualClock();
clock.advanceMillis(TimeUnit.SECONDS.toMillis(123));
ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
clock.advanceMillis(TimeUnit.SECONDS.toMillis(2));
// Start 10 actions (numbered 0 to 9).
for (int i = 0; i < 10; i++) {
clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
Action action = mockAction("Performing action A" + i + ".", "action_A" + i + ".out");
stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
}
// For various sample sizes verify the progress bar
for (int i = 1; i < 11; i++) {
stateTracker.setSampleSize(i);
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter);
String output = terminalWriter.getTranscript();
assertTrue("Action " + (i - 1) + " should still be shown in the output: '" + output, output.contains("A" + (i - 1) + "."));
assertFalse("Action " + i + " should not be shown in the output: " + output, output.contains("A" + i + "."));
if (i < 10) {
assertTrue("Ellipsis symbol should be shown in output: " + output, output.contains("..."));
} else {
assertFalse("Ellipsis symbol should not be shown in output: " + output, output.contains("..."));
}
}
}
use of com.google.devtools.build.lib.util.io.LoggingTerminalWriter in project bazel by bazelbuild.
the class ExperimentalStateTrackerTest method testDownloadOutputLength.
@Test
public void testDownloadOutputLength() throws Exception {
// Verify that URLs are shortened in a reasonable way, if the terminal is not wide enough
// Also verify that the length is respected, even if only a download sample is shown.
ManualClock clock = new ManualClock();
clock.advanceMillis(TimeUnit.SECONDS.toMillis(1234));
ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock, 60);
URL url = new URL("http://example.org/some/really/very/very/long/path/filename.tar.gz");
stateTracker.buildStarted(null);
stateTracker.downloadProgress(new DownloadProgressEvent(url));
clock.advanceMillis(TimeUnit.SECONDS.toMillis(6));
for (int i = 0; i < 10; i++) {
stateTracker.downloadProgress(new DownloadProgressEvent(new URL("http://otherhost.example/another/also/length/path/to/another/download" + i + ".zip")));
clock.advanceMillis(TimeUnit.SECONDS.toMillis(1));
}
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter);
String output = terminalWriter.getTranscript();
assertTrue("Only lines with at most 60 chars should be present in the output:\n" + output, longestLine(output) <= 60);
assertTrue("Output still should contain the filename, but was:\n" + output, output.contains("filename.tar.gz"));
assertTrue("Output still should contain the host name, but was:\n" + output, output.contains("example.org"));
}
use of com.google.devtools.build.lib.util.io.LoggingTerminalWriter in project bazel by bazelbuild.
the class ExperimentalStateTrackerTest method testSensibleShortening.
@Test
public void testSensibleShortening() throws Exception {
// Verify that in the typical case, we shorten the progress message by shortening
// the path implicit in it, that can also be extracted from the label. In particular,
// the parts
ManualClock clock = new ManualClock();
ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock, 70);
Action action = mockAction("Building some/very/very/long/path/for/some/library/directory/foo.jar (42 source files)", "/home/user/bazel/out/abcdef/some/very/very/long/path/for/some/library/directory/foo.jar");
Label label = Label.parseAbsolute("//some/very/very/long/path/for/some/library/directory:libfoo");
ActionOwner owner = ActionOwner.create(label, ImmutableList.<AspectDescriptor>of(), null, null, null, "fedcba", null);
when(action.getOwner()).thenReturn(owner);
clock.advanceMillis(TimeUnit.SECONDS.toMillis(3));
stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
clock.advanceMillis(TimeUnit.SECONDS.toMillis(5));
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter);
String output = terminalWriter.getTranscript();
assertTrue("Progress bar should contain 'Building ', but was:\n" + output, output.contains("Building "));
assertTrue("Progress bar should contain 'foo.jar (42 source files)', but was:\n" + output, output.contains("foo.jar (42 source files)"));
}
use of com.google.devtools.build.lib.util.io.LoggingTerminalWriter in project bazel by bazelbuild.
the class ExperimentalStateTrackerTest method doTestOutputLength.
private void doTestOutputLength(boolean withTest, int actions) throws Exception {
// If we target 70 characters, then there should be enough space to both,
// keep the line limit, and show the local part of the running actions and
// the passed test.
ManualClock clock = new ManualClock();
ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock, 70);
Action foobuildAction = mockAction("Building //src/some/very/long/path/long/long/long/long/long/long/long/foo/foobuild.jar", "//src/some/very/long/path/long/long/long/long/long/long/long/foo:foobuild");
Action bazbuildAction = mockAction("Building //src/some/very/long/path/long/long/long/long/long/long/long/baz/bazbuild.jar", "//src/some/very/long/path/long/long/long/long/long/long/long/baz:bazbuild");
Label bartestLabel = Label.parseAbsolute("//src/another/very/long/long/path/long/long/long/long/long/long/long/long/bars:bartest");
ConfiguredTarget bartestTarget = Mockito.mock(ConfiguredTarget.class);
when(bartestTarget.getLabel()).thenReturn(bartestLabel);
TestFilteringCompleteEvent filteringComplete = Mockito.mock(TestFilteringCompleteEvent.class);
when(filteringComplete.getTestTargets()).thenReturn(ImmutableSet.of(bartestTarget));
TestSummary testSummary = Mockito.mock(TestSummary.class);
when(testSummary.getStatus()).thenReturn(BlazeTestStatus.PASSED);
when(testSummary.getTarget()).thenReturn(bartestTarget);
if (actions >= 1) {
stateTracker.actionStarted(new ActionStartedEvent(foobuildAction, 123456789));
}
if (actions >= 2) {
stateTracker.actionStarted(new ActionStartedEvent(bazbuildAction, 123456900));
}
if (withTest) {
stateTracker.testFilteringComplete(filteringComplete);
stateTracker.testSummary(testSummary);
}
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
true);
stateTracker.writeProgressBar(terminalWriter);
String output = terminalWriter.getTranscript();
assertTrue("Only lines with at most 70 chars should be present in the output:\n" + output, longestLine(output) <= 70);
if (actions >= 1) {
assertTrue("Running action 'foobuild' should be mentioned in output:\n" + output, output.contains("foobuild"));
}
if (actions >= 2) {
assertTrue("Running action 'bazbuild' should be mentioned in output:\n" + output, output.contains("bazbuild"));
}
if (withTest) {
assertTrue("Passed test ':bartest' should be mentioned in output:\n" + output, output.contains(":bartest"));
}
}
Aggregations