Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
coeuvre committed Feb 14, 2023
1 parent 8488e71 commit d78e9be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,9 @@ private FileArtifactValue constructFileArtifactValue(
if (statAndValue.statNoFollow() != null
&& statAndValue.statNoFollow().isSymbolicLink()
&& statAndValue.realPath() != null) {
// If the file is a symlink, we compute the digest using the target path so that it's
// possible to hit the digest cache - we probably already computed the digest for the
// target during previous action execution.
path = statAndValue.realPath();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor;
import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.DigestUtils;
import com.google.devtools.build.lib.vfs.OutputPermissions;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
Expand Down Expand Up @@ -756,4 +757,29 @@ public void fileArtifactValueFromArtifactCompatibleWithGetMetadata_notChanged()
assertThat(fileArtifactValueFromArtifactResult.couldBeModifiedSince(getMetadataResult))
.isFalse();
}

@Test
public void fileArtifactValueForSymlink_readFromCache() throws Exception {
DigestUtils.configureCache(1);
Artifact target =
ActionsTestUtil.createArtifactWithRootRelativePath(
outputRoot, PathFragment.create("bin/target"));
scratch.file(target.getPath().getPathString(), "contents");
Artifact symlink =
ActionsTestUtil.createArtifactWithRootRelativePath(
outputRoot, PathFragment.create("bin/symlink"));
scratch.getFileSystem().getPath(symlink.getPath().getPathString()).createSymbolicLink(scratch.getFileSystem().getPath(target.getPath().getPathString()));
ActionMetadataHandler handler =
createHandler(
new ActionInputMap(0),
/*forInputDiscovery=*/ false,
/*outputs=*/ ImmutableSet.of(target, symlink));
var targetMetadata = handler.getMetadata(target);
assertThat(DigestUtils.getCacheStats().hitCount()).isEqualTo(0);

var symlinkMetadata = handler.getMetadata(symlink);

assertThat(symlinkMetadata).isEqualTo(targetMetadata);
assertThat(DigestUtils.getCacheStats().hitCount()).isEqualTo(1);
}
}

0 comments on commit d78e9be

Please sign in to comment.