Search in sources :

Example 1 with TestFilteringCompleteEvent

use of com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent 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"));
}
Also used : ManualClock(com.google.devtools.build.lib.testutil.ManualClock) ActionOwner(com.google.devtools.build.lib.actions.ActionOwner) 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) Test(org.junit.Test)

Example 2 with TestFilteringCompleteEvent

use of com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent 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 3 with TestFilteringCompleteEvent

use of com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent 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 4 with TestFilteringCompleteEvent

use of com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent in project bazel by bazelbuild.

the class ExperimentalStateTrackerTest method testPassedVisible.

@Test
public void testPassedVisible() throws Exception {
    // The last test should still be visible in the long status bar, and colored as ok if it passed.
    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.getStatus()).thenReturn(BlazeTestStatus.PASSED);
    when(testSummary.getTarget()).thenReturn(targetA);
    stateTracker.testFilteringComplete(filteringComplete);
    stateTracker.testSummary(testSummary);
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter();
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    String expected = LoggingTerminalWriter.OK + labelA;
    assertTrue("Sequence '" + expected + "' should be present in colored progress bar: " + output, output.contains(expected));
}
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 5 with TestFilteringCompleteEvent

use of com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent in project bazel by bazelbuild.

the class ExperimentalStateTrackerTest method testFailedVisible.

@Test
public void testFailedVisible() throws Exception {
    // The last test should still be visible in the long status bar, and colored as fail if it
    // did not pass.
    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.getStatus()).thenReturn(BlazeTestStatus.FAILED);
    when(testSummary.getTarget()).thenReturn(targetA);
    stateTracker.testFilteringComplete(filteringComplete);
    stateTracker.testSummary(testSummary);
    LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter();
    stateTracker.writeProgressBar(terminalWriter);
    String output = terminalWriter.getTranscript();
    String expected = LoggingTerminalWriter.FAIL + labelA;
    assertTrue("Sequence '" + expected + "' should be present in colored progress bar: " + output, output.contains(expected));
}
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)

Aggregations

TestFilteringCompleteEvent (com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent)6 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)5 Label (com.google.devtools.build.lib.cmdline.Label)5 ManualClock (com.google.devtools.build.lib.testutil.ManualClock)5 LoggingTerminalWriter (com.google.devtools.build.lib.util.io.LoggingTerminalWriter)5 Test (org.junit.Test)4 Action (com.google.devtools.build.lib.actions.Action)2 ActionStartedEvent (com.google.devtools.build.lib.actions.ActionStartedEvent)2 Stopwatch (com.google.common.base.Stopwatch)1 ActionOwner (com.google.devtools.build.lib.actions.ActionOwner)1 AnalysisPhaseCompleteEvent (com.google.devtools.build.lib.analysis.AnalysisPhaseCompleteEvent)1 BuildView (com.google.devtools.build.lib.analysis.BuildView)1 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)1