diff options
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/skyframe')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java | 63 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactMetadataTest.java | 4 |
2 files changed, 57 insertions, 10 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java index ccf282243f..7637abd3ba 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.fail; import com.google.common.io.BaseEncoding; import com.google.common.testing.EqualsTester; +import com.google.devtools.build.lib.testutil.ManualClock; import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; @@ -30,11 +31,12 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class FileArtifactValueTest { - private final FileSystem fs = new InMemoryFileSystem(); + private final ManualClock clock = new ManualClock(); + private final FileSystem fs = new InMemoryFileSystem(clock); private Path scratchFile(String name, long mtime, String content) throws IOException { Path path = fs.getPath(name); - FileSystemUtils.createDirectoryAndParents(path.getParentDirectory()); + path.getParentDirectory().createDirectoryAndParents(); FileSystemUtils.writeContentAsLatin1(path, content); path.setLastModifiedTime(mtime); return path; @@ -42,7 +44,7 @@ public class FileArtifactValueTest { private Path scratchDir(String name, long mtime) throws IOException { Path path = fs.getPath(name); - FileSystemUtils.createDirectoryAndParents(path); + path.createDirectoryAndParents(); path.setLastModifiedTime(mtime); return path; } @@ -114,9 +116,7 @@ public class FileArtifactValueTest { @Test public void testDirectory() throws Exception { - Path path = fs.getPath("/dir"); - FileSystemUtils.createDirectoryAndParents(path); - path.setLastModifiedTime(1L); + Path path = scratchDir("/dir", /*mtime=*/ 1L); FileArtifactValue value = create(path); assertThat(value.getDigest()).isNull(); assertThat(value.getModifiedTime()).isEqualTo(1L); @@ -153,7 +153,7 @@ public class FileArtifactValueTest { } }; Path path = fs.getPath("/some/path"); - FileSystemUtils.createDirectoryAndParents(path.getParentDirectory()); + path.getParentDirectory().createDirectoryAndParents(); FileSystemUtils.writeContentAsLatin1(path, "content"); try { create(path); @@ -162,4 +162,53 @@ public class FileArtifactValueTest { assertThat(e).isSameAs(exception); } } + + @Test + public void testUptodateCheck() throws Exception { + Path path = scratchFile("/dir/artifact1", 0L, "content"); + FileArtifactValue value = create(path); + clock.advanceMillis(1); + assertThat(value.wasModifiedSinceDigest(path)).isFalse(); + clock.advanceMillis(1); + assertThat(value.wasModifiedSinceDigest(path)).isFalse(); + clock.advanceMillis(1); + path.setLastModifiedTime(123); // Changing mtime implicitly updates ctime. + assertThat(value.wasModifiedSinceDigest(path)).isTrue(); + clock.advanceMillis(1); + assertThat(value.wasModifiedSinceDigest(path)).isTrue(); + } + + @Test + public void testUptodateCheckDeleteFile() throws Exception { + Path path = scratchFile("/dir/artifact1", 0L, "content"); + FileArtifactValue value = create(path); + assertThat(value.wasModifiedSinceDigest(path)).isFalse(); + path.delete(); + assertThat(value.wasModifiedSinceDigest(path)).isTrue(); + } + + @Test + public void testUptodateCheckDirectory() throws Exception { + // For now, we don't attempt to detect changes to directories. + Path path = scratchDir("/dir", 0L); + FileArtifactValue value = create(path); + assertThat(value.wasModifiedSinceDigest(path)).isFalse(); + path.delete(); + clock.advanceMillis(1); + assertThat(value.wasModifiedSinceDigest(path)).isFalse(); + } + + @Test + public void testUptodateChangeFileToDirectory() throws Exception { + // For now, we don't attempt to detect changes to directories. + Path path = scratchFile("/dir/file", 0L, ""); + FileArtifactValue value = create(path); + assertThat(value.wasModifiedSinceDigest(path)).isFalse(); + // If we only check ctime, then we need to change the clock here, or we get a ctime match on the + // stat. + path.delete(); + path.createDirectoryAndParents(); + clock.advanceMillis(1); + assertThat(value.wasModifiedSinceDigest(path)).isTrue(); + } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactMetadataTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactMetadataTest.java index 3c32a9df3d..4e3b242b5d 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactMetadataTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactMetadataTest.java @@ -102,9 +102,7 @@ public class TreeArtifactMetadataTest extends ArtifactFunctionTestCase { // breaking changes. Map<String, Metadata> digestBuilder = new HashMap<>(); for (PathFragment child : children) { - Metadata subdigest = FileArtifactValue.createNormalFile( - tree.getPath().getRelative(child).getDigest(), - tree.getPath().getRelative(child).getFileSize()); + Metadata subdigest = FileArtifactValue.create(tree.getPath().getRelative(child)); digestBuilder.put(child.getPathString(), subdigest); } assertThat(DigestUtils.fromMetadata(digestBuilder).getDigestBytesUnsafe()) |