Skip to content

Commit cdf6784

Browse files
authored
Make runfiles handling more realistic and Improve test coverage of remote worker files
1 parent 86fd20a commit cdf6784

File tree

1 file changed

+80
-8
lines changed

1 file changed

+80
-8
lines changed

src/test/java/com/google/devtools/build/lib/remote/RemoteExecutionServiceTest.java

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
import com.google.devtools.build.lib.remote.util.TracingMetadataUtils;
120120
import com.google.devtools.build.lib.remote.util.Utils.InMemoryOutput;
121121
import com.google.devtools.build.lib.skyframe.TreeArtifactValue;
122+
import com.google.devtools.build.lib.testutil.TestConstants;
122123
import com.google.devtools.build.lib.util.Fingerprint;
123124
import com.google.devtools.build.lib.util.OS;
124125
import com.google.devtools.build.lib.util.TempPathGenerator;
@@ -2327,16 +2328,28 @@ public void buildMerkleTree_withMemoization_works() throws Exception {
23272328
}
23282329

23292330
@Test
2330-
public void buildRemoteActionForRemotePersistentWorkers() throws Exception {
2331+
public void buildRemoteActionForRemotePersistentWorkers(@TestParameter boolean enablePathMapping)
2332+
throws Exception {
23312333
var input = ActionsTestUtil.createArtifact(artifactRoot, "input");
23322334
fakeFileCache.createScratchInput(input, "value");
23332335
var toolInput = ActionsTestUtil.createArtifact(artifactRoot, "worker_input");
23342336
fakeFileCache.createScratchInput(toolInput, "worker value");
2337+
2338+
Artifact toolDat = ActionsTestUtil.createArtifact(artifactRoot, "tool.dat");
2339+
fakeFileCache.createScratchInput(toolDat, "tool.dat");
2340+
RunfilesTree runfilesTree =
2341+
createRunfilesTree("outputs/worker_input.runfiles", ImmutableList.of(toolDat));
2342+
ActionInput runfilesArtifact =
2343+
ActionsTestUtil.createRunfilesArtifact(artifactRoot, "outputs/worker_input.runfiles");
2344+
fakeFileCache.addRunfilesTree(runfilesArtifact, runfilesTree);
2345+
23352346
Spawn spawn =
23362347
new SpawnBuilder("@flagfile")
23372348
.withExecutionInfo(ExecutionRequirements.SUPPORTS_WORKERS, "1")
2338-
.withInputs(input, toolInput)
2339-
.withTool(toolInput)
2349+
.withInputs(input, toolInput, runfilesArtifact)
2350+
.withTools(toolInput, runfilesArtifact)
2351+
.setPathMapper(
2352+
enablePathMapping ? path -> PathFragment.create("mapped_" + path) : PathMapper.NOOP)
23402353
.build();
23412354
FakeSpawnExecutionContext context = newSpawnExecutionContext(spawn);
23422355
remoteOptions.markToolInputs = true;
@@ -2352,7 +2365,9 @@ public void buildRemoteActionForRemotePersistentWorkers() throws Exception {
23522365
Platform.Property.newBuilder()
23532366
.setName("persistentWorkerKey")
23542367
.setValue(
2355-
"628637504c26bb74fb6bb3f60fb7132b3aa574b866db4181770774882a8853e5"))
2368+
enablePathMapping
2369+
? "85e3ad12f36ccb7b5eddbfe8f6bc28f57004634c537faac32d33a30b8d456bb8"
2370+
: "5b1f31685d47bab5267d65bf671a682a486240ae351d74130a12d452190bd5f3"))
23562371
.build());
23572372
var merkleTree = remoteAction.getMerkleTree();
23582373
var outputDirectory =
@@ -2376,8 +2391,55 @@ public void buildRemoteActionForRemotePersistentWorkers() throws Exception {
23762391
.setNodeProperties(
23772392
NodeProperties.newBuilder()
23782393
.addProperties(NodeProperty.newBuilder().setName("bazel_tool_input")));
2394+
var toolRunfilesDirectoryDigest =
2395+
Digest.newBuilder()
2396+
.setHash("d5cf7403c6b6c97f7b404c829a3d70c618412411c4554ed29b0f59815c53d952")
2397+
.setSizeBytes(79)
2398+
.build();
2399+
var toolRunfilesDirectory =
2400+
DirectoryNode.newBuilder()
2401+
.setName("worker_input.runfiles")
2402+
.setDigest(toolRunfilesDirectoryDigest);
23792403
assertThat(outputDirectory)
2380-
.isEqualTo(Directory.newBuilder().addFiles(inputFile).addFiles(toolFile).build());
2404+
.isEqualTo(
2405+
Directory.newBuilder()
2406+
.addFiles(inputFile)
2407+
.addFiles(toolFile)
2408+
.addDirectories(toolRunfilesDirectory)
2409+
.build());
2410+
var runfilesDirectory = merkleTree.getDirectoryByDigest(toolRunfilesDirectoryDigest);
2411+
var runfilesSubdirectoryDigest =
2412+
Digest.newBuilder()
2413+
.setHash("2773ed2d89aed9db55b83230eb8c66f56a02884e151009a3b070164bb6800cc8")
2414+
.setSizeBytes(106)
2415+
.build();
2416+
assertThat(runfilesDirectory)
2417+
.isEqualTo(
2418+
Directory.newBuilder()
2419+
.addDirectories(
2420+
DirectoryNode.newBuilder()
2421+
.setName(TestConstants.WORKSPACE_NAME)
2422+
.setDigest(runfilesSubdirectoryDigest))
2423+
.build());
2424+
var runfilesSubdirectory = merkleTree.getDirectoryByDigest(runfilesSubdirectoryDigest);
2425+
assertThat(runfilesSubdirectory)
2426+
.isEqualTo(
2427+
Directory.newBuilder()
2428+
.addFiles(
2429+
FileNode.newBuilder()
2430+
.setName("tool.dat")
2431+
.setDigest(
2432+
Digest.newBuilder()
2433+
.setHash(
2434+
"968b7e2e112917824f4ea807dbc3adeebc00de2836f98c68418f525295f9a0c1")
2435+
.setSizeBytes(8))
2436+
.setIsExecutable(true)
2437+
.setNodeProperties(
2438+
NodeProperties.newBuilder()
2439+
.addProperties(
2440+
NodeProperty.newBuilder().setName("bazel_tool_input")))
2441+
.build())
2442+
.build());
23812443

23822444
// Check that if an non-tool input changes, the persistent worker key does not change.
23832445
fakeFileCache.createScratchInput(input, "value2");
@@ -2388,7 +2450,9 @@ public void buildRemoteActionForRemotePersistentWorkers() throws Exception {
23882450
Platform.Property.newBuilder()
23892451
.setName("persistentWorkerKey")
23902452
.setValue(
2391-
"628637504c26bb74fb6bb3f60fb7132b3aa574b866db4181770774882a8853e5"))
2453+
enablePathMapping
2454+
? "85e3ad12f36ccb7b5eddbfe8f6bc28f57004634c537faac32d33a30b8d456bb8"
2455+
: "5b1f31685d47bab5267d65bf671a682a486240ae351d74130a12d452190bd5f3"))
23922456
.build());
23932457

23942458
// Check that if a tool input changes, the persistent worker key changes.
@@ -2400,7 +2464,9 @@ public void buildRemoteActionForRemotePersistentWorkers() throws Exception {
24002464
Platform.Property.newBuilder()
24012465
.setName("persistentWorkerKey")
24022466
.setValue(
2403-
"98e07ff5afc8f4d127e93d326c87c132f89cfd009517422671e6abec2fe05e2b"))
2467+
enablePathMapping
2468+
? "6667700b8ff75e77f50c0d6b471e9052c856a21648c8204f0772fc455df6d6dc"
2469+
: "63335231cbbf2ff838acdd19da768ce6524e929c4dcedcdce77c822a480fa49b"))
24042470
.build());
24052471
}
24062472

@@ -2685,7 +2751,13 @@ public PathFragment getExecPath() {
26852751
@Override
26862752
public SortedMap<PathFragment, Artifact> getMapping() {
26872753
return artifacts.stream()
2688-
.collect(toImmutableSortedMap(naturalOrder(), Artifact::getExecPath, identity()));
2754+
.collect(
2755+
toImmutableSortedMap(
2756+
naturalOrder(),
2757+
artifact ->
2758+
PathFragment.create(TestConstants.WORKSPACE_NAME)
2759+
.getRelative(artifact.getRunfilesPath()),
2760+
identity()));
26892761
}
26902762

26912763
@Override

0 commit comments

Comments
 (0)