Search in sources :

Example 6 with ManualClock

use of com.google.devtools.build.lib.testutil.ManualClock 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));
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ManualClock(com.google.devtools.build.lib.testutil.ManualClock) ActionExecutionMetadata(com.google.devtools.build.lib.actions.ActionExecutionMetadata) ActionOwner(com.google.devtools.build.lib.actions.ActionOwner) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) Artifact(com.google.devtools.build.lib.actions.Artifact) LoggingTerminalWriter(com.google.devtools.build.lib.util.io.LoggingTerminalWriter) Test(org.junit.Test)

Example 7 with ManualClock

use of com.google.devtools.build.lib.testutil.ManualClock 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"));
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) DownloadProgressEvent(com.google.devtools.build.lib.bazel.repository.downloader.DownloadProgressEvent) URL(java.net.URL) LoggingTerminalWriter(com.google.devtools.build.lib.util.io.LoggingTerminalWriter) Test(org.junit.Test)

Example 8 with ManualClock

use of com.google.devtools.build.lib.testutil.ManualClock 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"));
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) Label(com.google.devtools.build.lib.cmdline.Label) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) TestFilteringCompleteEvent(com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent) LoggingTerminalWriter(com.google.devtools.build.lib.util.io.LoggingTerminalWriter) Test(org.junit.Test)

Example 9 with ManualClock

use of com.google.devtools.build.lib.testutil.ManualClock 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("..."));
        }
    }
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) Action(com.google.devtools.build.lib.actions.Action) ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) LoggingTerminalWriter(com.google.devtools.build.lib.util.io.LoggingTerminalWriter) Test(org.junit.Test)

Example 10 with ManualClock

use of com.google.devtools.build.lib.testutil.ManualClock 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"));
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) DownloadProgressEvent(com.google.devtools.build.lib.bazel.repository.downloader.DownloadProgressEvent) URL(java.net.URL) LoggingTerminalWriter(com.google.devtools.build.lib.util.io.LoggingTerminalWriter) Test(org.junit.Test)

Aggregations

ManualClock (com.google.devtools.build.lib.testutil.ManualClock)23 Test (org.junit.Test)16 LoggingTerminalWriter (com.google.devtools.build.lib.util.io.LoggingTerminalWriter)15 ActionStartedEvent (com.google.devtools.build.lib.actions.ActionStartedEvent)10 Label (com.google.devtools.build.lib.cmdline.Label)6 Before (org.junit.Before)6 Action (com.google.devtools.build.lib.actions.Action)5 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)5 TestFilteringCompleteEvent (com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent)5 ActionOwner (com.google.devtools.build.lib.actions.ActionOwner)3 InMemoryFileSystem (com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem)3 DownloadProgressEvent (com.google.devtools.build.lib.bazel.repository.downloader.DownloadProgressEvent)2 Path (com.google.devtools.build.lib.vfs.Path)2 URL (java.net.URL)2 ActionCompletionEvent (com.google.devtools.build.lib.actions.ActionCompletionEvent)1 ActionExecutionMetadata (com.google.devtools.build.lib.actions.ActionExecutionMetadata)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 PathPackageLocator (com.google.devtools.build.lib.pkgcache.PathPackageLocator)1 LoadingPhaseStartedEvent (com.google.devtools.build.lib.skyframe.LoadingPhaseStartedEvent)1 PackageProgressReceiver (com.google.devtools.build.lib.skyframe.PackageProgressReceiver)1