diff options
author | 2017-02-08 18:21:11 +0000 | |
---|---|---|
committer | 2017-02-09 15:09:37 +0000 | |
commit | e16c564b9d9cd4ee983ca7ae580000111fd12dda (patch) | |
tree | 9dae21422b72d4a22c19df0d36d3047bb79513f7 /src/test/java/com/google/devtools/build/lib/skyframe | |
parent | 26f858c9cda88c45da98f8df2090417042bac2f3 (diff) |
Introduce a new SkyValue that merely contains the workspace name. The workspace name is needed for package loading, and so splitting out this computation into a separate skyframe node that can be change-pruned gives us better incrementality; previously we'd need to reload all packages on a WORKSPACE file change.
N.B.
(i) This CL doesn't solve all the other performance issues with //external in Bazel/Blaze since it's still inefficiently used for resolving labels like @foo//bar:baz.
(ii) This CL doesn't address the wasteful invalidation + change pruning of all the packages.
--
PiperOrigin-RevId: 146925369
MOS_MIGRATED_REVID=146925369
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/skyframe')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceNameFunctionTest.java | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceNameFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceNameFunctionTest.java new file mode 100644 index 0000000000..fbb1e644ef --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceNameFunctionTest.java @@ -0,0 +1,89 @@ +// Copyright 2017 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 com.google.devtools.build.skyframe.EvaluationResultSubjectFactory.assertThatEvaluationResult; + +import com.google.common.testing.EqualsTester; +import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; +import com.google.devtools.build.lib.packages.NoSuchPackageException; +import com.google.devtools.build.lib.skyframe.util.SkyframeExecutorTestUtils; +import com.google.devtools.build.lib.vfs.FileSystemUtils; +import com.google.devtools.build.lib.vfs.ModifiedFileSet; +import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.skyframe.EvaluationResult; +import com.google.devtools.build.skyframe.SkyKey; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for {@link WorkspaceNameValue} and {@link WorkspaceNameFunction}. */ +@RunWith(JUnit4.class) +public class WorkspaceNameFunctionTest extends BuildViewTestCase { + private final SkyKey key = WorkspaceNameValue.key(); + + private EvaluationResult<WorkspaceNameValue> eval() throws InterruptedException { + getSkyframeExecutor().invalidateFilesUnderPathForTesting( + reporter, + ModifiedFileSet.builder().modify(new PathFragment("WORKSPACE")).build(), + rootDirectory); + return SkyframeExecutorTestUtils.evaluate( + getSkyframeExecutor(), key, /*keepGoing=*/ false, reporter); + } + + @Test + public void testNormal() throws Exception { + scratch.overwriteFile("WORKSPACE", "workspace(name = 'good')"); + assertThatEvaluationResult(eval()) + .hasEntryThat(key) + .isEqualTo(WorkspaceNameValue.withName("good")); + } + + @Test + public void testErrorInExternalPkg() throws Exception { + reporter.removeHandler(failFastHandler); + scratch.overwriteFile("WORKSPACE", "workspace(bad)"); + assertThatEvaluationResult(eval()) + .hasEntryThat(key) + .isEqualTo(WorkspaceNameValue.withError()); + assertContainsEvent("name 'bad' is not defined"); + } + + @Test + public void testTransitiveSkyframeError() throws Exception { + reporter.removeHandler(failFastHandler); + scratch.deleteFile("WORKSPACE"); + FileSystemUtils.ensureSymbolicLink(scratch.resolve("WORKSPACE"), "WORKSPACE"); + // Transitive errors from WorkspaceNameValue should manifest themselves as + // NoSuchPackageExceptions. + assertThatEvaluationResult(eval()) + .hasErrorEntryForKeyThat(key) + .hasExceptionThat() + .isInstanceOf(NoSuchPackageException.class); + } + + @Test + public void testEqualsAndHashCode(){ + new EqualsTester() + .addEqualityGroup( + WorkspaceNameValue.withError(), + WorkspaceNameValue.withError()) + .addEqualityGroup( + WorkspaceNameValue.withName("foo"), + WorkspaceNameValue.withName("foo")) + .addEqualityGroup( + WorkspaceNameValue.withName("bar"), + WorkspaceNameValue.withName("bar")); + } +} |