diff options
author | 2016-05-27 11:42:32 +0000 | |
---|---|---|
committer | 2016-05-30 09:17:25 +0000 | |
commit | c6fd6bb3caa78518fbb9148d81efecdee540c29a (patch) | |
tree | 2b7cd0063ad4da4b4fe6c0c633e9e5fc45ac7534 /src/test | |
parent | 2fba42e27ec517a8819236d15e45a42bfd5c1823 (diff) |
experimental UI: track touched packages during loading/analysis
To give a better understanding of which packages are on the critical
path during loading and analysis, provide information in the same way
as during execution: show the earliest started, but not yet completed
package. As not all packages looked at during the analysis phase are
reported to the progress receiver, use a custom class to aggregate those
data.
--
Change-Id: I03c25efdecb4124e1bc06fce8be9175dc56b5500
Reviewed-on: https://bazel-review.googlesource.com/#/c/3700
MOS_MIGRATED_REVID=123408689
Diffstat (limited to 'src/test')
3 files changed, 110 insertions, 1 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java index a276bc516b..ae6ec139cf 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java @@ -27,9 +27,12 @@ import com.google.devtools.build.lib.actions.Root; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.skyframe.LoadingPhaseStartedEvent; +import com.google.devtools.build.lib.skyframe.PackageProgressReceiver; import com.google.devtools.build.lib.testutil.FoundationTestCase; import com.google.devtools.build.lib.testutil.LoggingTerminalWriter; import com.google.devtools.build.lib.testutil.ManualClock; +import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus; @@ -67,6 +70,35 @@ public class ExperimentalStateTrackerTest extends FoundationTestCase { } @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)); + } + + @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. diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PackageProgressReceiverTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PackageProgressReceiverTest.java new file mode 100644 index 0000000000..df35718a42 --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/skyframe/PackageProgressReceiverTest.java @@ -0,0 +1,77 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.skyframe; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import com.google.devtools.build.lib.cmdline.PackageIdentifier; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Tests {@link PackageProgressReceiver}. + */ +@RunWith(JUnit4.class) +public class PackageProgressReceiverTest { + + @Test + public void testPackageVisible() { + // If there is only a single package being loaded, it is visible in + // the activity part of the progress state. + PackageIdentifier id = PackageIdentifier.createInMainRepo("foo/bar/baz"); + PackageProgressReceiver progress = new PackageProgressReceiver(); + progress.startReadPackage(id); + String activity = progress.progressState().getSecond(); + + assertTrue( + "Unfinished package '" + id + "' should be visible in activity: " + activity, + activity.contains(id.toString())); + } + + @Test + public void testPackageCounted() { + // If the loading of a package is completed, it is no longer visible as activity, + // but counted as one package fully loaded. + PackageIdentifier id = PackageIdentifier.createInMainRepo("foo/bar/baz"); + PackageProgressReceiver progress = new PackageProgressReceiver(); + progress.startReadPackage(id); + progress.doneReadPackage(id); + String state = progress.progressState().getFirst(); + String activity = progress.progressState().getSecond(); + + assertFalse( + "Finished package '" + id + "' should not be visible in activity: " + activity, + activity.contains(id.toString())); + assertTrue( + "Number of completed packages should be visible in state", state.contains("1 package")); + } + + @Test + public void testReset() { + // After resetting, messages should be as immediately after creation. + PackageProgressReceiver progress = new PackageProgressReceiver(); + String defaultState = progress.progressState().getFirst(); + String defaultActivity = progress.progressState().getSecond(); + PackageIdentifier id = PackageIdentifier.createInMainRepo("foo/bar/baz"); + progress.startReadPackage(id); + progress.doneReadPackage(id); + progress.reset(); + assertEquals(defaultState, progress.progressState().getFirst()); + assertEquals(defaultActivity, progress.progressState().getSecond()); + } +} diff --git a/src/test/shell/integration/experimental_ui_test.sh b/src/test/shell/integration/experimental_ui_test.sh index 490d0fe747..3734b7bb24 100755 --- a/src/test/shell/integration/experimental_ui_test.sh +++ b/src/test/shell/integration/experimental_ui_test.sh @@ -198,7 +198,7 @@ function test_loading_progress { --experimental_skyframe_target_pattern_evaluator pkg:true 2>$TEST_log \ || fail "bazel test failed" # some progress indicator is shown during loading - expect_log 'Loading.*[0-9,]* / [0-9,]*' + expect_log 'Loading.*[0-9,]* packages' } function test_failure_scrollback_buffer_curses { |