forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update GetActionResult for disk cache to check referenced files when …
…building without the bytes. Closes bazelbuild#16731. PiperOrigin-RevId: 490262565 Change-Id: I342ec2371b81b9e23fc7935e30d5fed8fb6d4005
- Loading branch information
1 parent
7201e74
commit 23ffce5
Showing
7 changed files
with
240 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
src/test/java/com/google/devtools/build/lib/remote/DiskCacheIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// Copyright 2022 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.remote; | ||
|
||
import static com.google.devtools.build.lib.testutil.TestUtils.tmpDirFile; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.devtools.build.lib.buildtool.util.BuildIntegrationTestCase; | ||
import com.google.devtools.build.lib.runtime.BlazeModule; | ||
import com.google.devtools.build.lib.runtime.BlazeRuntime; | ||
import com.google.devtools.build.lib.runtime.BlockWaitingModule; | ||
import com.google.devtools.build.lib.runtime.BuildSummaryStatsModule; | ||
import com.google.devtools.build.lib.standalone.StandaloneModule; | ||
import com.google.devtools.build.lib.vfs.PathFragment; | ||
import java.io.IOException; | ||
import org.junit.After; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public class DiskCacheIntegrationTest extends BuildIntegrationTestCase { | ||
|
||
private static PathFragment getDiskCacheDir() { | ||
PathFragment testTmpDir = PathFragment.create(tmpDirFile().getAbsolutePath()); | ||
return testTmpDir.getRelative("disk_cache"); | ||
} | ||
|
||
@Override | ||
protected void setupOptions() throws Exception { | ||
super.setupOptions(); | ||
|
||
addOptions("--disk_cache=" + getDiskCacheDir()); | ||
} | ||
|
||
@After | ||
public void tearDown() throws IOException { | ||
getWorkspace().getFileSystem().getPath(getDiskCacheDir()).deleteTree(); | ||
} | ||
|
||
@Override | ||
protected ImmutableList<BlazeModule> getSpawnModules() { | ||
return ImmutableList.<BlazeModule>builder() | ||
.addAll(super.getSpawnModules()) | ||
.add(new StandaloneModule()) | ||
.build(); | ||
} | ||
|
||
@Override | ||
protected BlazeRuntime.Builder getRuntimeBuilder() throws Exception { | ||
return super.getRuntimeBuilder() | ||
.addBlazeModule(new RemoteModule()) | ||
.addBlazeModule(new BuildSummaryStatsModule()) | ||
.addBlazeModule(new BlockWaitingModule()); | ||
} | ||
|
||
@Test | ||
public void hitDiskCache() throws Exception { | ||
write( | ||
"BUILD", | ||
"genrule(", | ||
" name = 'foo',", | ||
" srcs = ['foo.in'],", | ||
" outs = ['foo.out'],", | ||
" cmd = 'cat $(SRCS) > $@',", | ||
")", | ||
"genrule(", | ||
" name = 'foobar',", | ||
" srcs = [':foo.out', 'bar.in'],", | ||
" outs = ['foobar.out'],", | ||
" cmd = 'cat $(SRCS) > $@',", | ||
")"); | ||
write("foo.in", "foo"); | ||
write("bar.in", "bar"); | ||
buildTarget("//:foobar"); | ||
cleanAndRestartServer(); | ||
|
||
buildTarget("//:foobar"); | ||
|
||
events.assertContainsInfo("2 disk cache hit"); | ||
} | ||
|
||
private void blobsReferencedInAAreMissingCasIgnoresAc(String... additionalOptions) | ||
throws Exception { | ||
// Arrange: Prepare the workspace and populate disk cache | ||
write( | ||
"BUILD", | ||
"genrule(", | ||
" name = 'foo',", | ||
" srcs = ['foo.in'],", | ||
" outs = ['foo.out'],", | ||
" cmd = 'cat $(SRCS) > $@',", | ||
")", | ||
"genrule(", | ||
" name = 'foobar',", | ||
" srcs = [':foo.out', 'bar.in'],", | ||
" outs = ['foobar.out'],", | ||
" cmd = 'cat $(SRCS) > $@',", | ||
")"); | ||
write("foo.in", "foo"); | ||
write("bar.in", "bar"); | ||
addOptions(additionalOptions); | ||
buildTarget("//:foobar"); | ||
cleanAndRestartServer(); | ||
|
||
// Act: Delete blobs in CAS from disk cache and do a clean build | ||
getWorkspace().getFileSystem().getPath(getDiskCacheDir().getRelative("cas")).deleteTree(); | ||
addOptions(additionalOptions); | ||
buildTarget("//:foobar"); | ||
|
||
// Assert: Should ignore the stale AC and rerun the generating action | ||
events.assertDoesNotContainEvent("disk cache hit"); | ||
} | ||
|
||
@Test | ||
public void blobsReferencedInAcAreMissingCas_ignoresAc() throws Exception { | ||
blobsReferencedInAAreMissingCasIgnoresAc(); | ||
} | ||
|
||
@Test | ||
public void bwob_blobsReferencedInAcAreMissingCas_ignoresAc() throws Exception { | ||
blobsReferencedInAAreMissingCasIgnoresAc("--remote_download_minimal"); | ||
} | ||
|
||
private void cleanAndRestartServer() throws Exception { | ||
getOutputBase().getRelative("action_cache").deleteTreesBelow(); | ||
// Simulates a server restart | ||
createRuntimeWrapper(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters