Search in sources :

Example 11 with ManualClock

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

Example 12 with ManualClock

use of com.google.devtools.build.lib.testutil.ManualClock 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"));
    }
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) Action(com.google.devtools.build.lib.actions.Action) Label(com.google.devtools.build.lib.cmdline.Label) ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) 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)

Example 13 with ManualClock

use of com.google.devtools.build.lib.testutil.ManualClock in project bazel by bazelbuild.

the class FileSystemUtilsTest method initializeFileSystem.

@Before
public final void initializeFileSystem() throws Exception {
    clock = new ManualClock();
    fileSystem = new InMemoryFileSystem(clock);
    workingDir = fileSystem.getPath("/workingDir");
    workingDir.createDirectory();
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) Before(org.junit.Before)

Example 14 with ManualClock

use of com.google.devtools.build.lib.testutil.ManualClock in project bazel by bazelbuild.

the class SymlinkForestTest method initializeFileSystem.

@Before
public final void initializeFileSystem() throws Exception {
    ManualClock clock = new ManualClock();
    fileSystem = new InMemoryFileSystem(clock);
    linkRoot = fileSystem.getPath("/linkRoot");
    createDirectoryAndParents(linkRoot);
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) Before(org.junit.Before)

Example 15 with ManualClock

use of com.google.devtools.build.lib.testutil.ManualClock in project bazel by bazelbuild.

the class ExperimentalStateTrackerTest method testActionVisible.

@Test
public void testActionVisible() throws IOException {
    // If there is only one action running, it should be visible
    // somewhere in the progress bar, and also the short version thereof.
    String message = "Building foo";
    ManualClock clock = new ManualClock();
    clock.advanceMillis(120000);
    ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
    stateTracker.actionStarted(new ActionStartedEvent(mockAction(message, "bar/foo"), 123456789));
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/
    true);
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    assertTrue("Action message '" + message + "' should be present in output: " + output, output.contains(message));
    terminalWriter = new LoggingTerminalWriter();
    stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/
    true);
    output = terminalWriter.getTranscript();
    assertTrue("Action message '" + message + "' should be present in short output: " + output, output.contains(message));
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) 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