Update FilesystemValueCheckerTest to use a TimestampGranularityMonitor and to test for cases when the file size does not change.
RELNOTES: None.
PiperOrigin-RevId: 261649236
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java
index cb06db2..a823807 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java
@@ -39,6 +39,7 @@
import com.google.devtools.build.lib.actions.util.TestAction;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.ServerDirectories;
+import com.google.devtools.build.lib.clock.BlazeClock;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.events.NullEventHandler;
import com.google.devtools.build.lib.packages.WorkspaceFileValue;
@@ -369,6 +370,7 @@
FileSystemUtils.writeContentAsLatin1(out1.getPath(), "hello");
FileSystemUtils.writeContentAsLatin1(out2.getPath(), "fizzlepop");
+ TimestampGranularityMonitor tsgm = new TimestampGranularityMonitor(BlazeClock.instance());
ActionLookupKey actionLookupKey =
new ActionLookupKey() {
@Override
@@ -378,6 +380,35 @@
};
SkyKey actionKey1 = ActionLookupData.create(actionLookupKey, 0);
SkyKey actionKey2 = ActionLookupData.create(actionLookupKey, 1);
+
+ pretendBuildTwoArtifacts(out1, actionKey1, out2, actionKey2, batchStatter, tsgm);
+
+ // Change the file but not its size
+ FileSystemUtils.writeContentAsLatin1(out1.getPath(), "hallo");
+ checkActionDirtiedByFile(out1, actionKey1, batchStatter, tsgm);
+ pretendBuildTwoArtifacts(out1, actionKey1, out2, actionKey2, batchStatter, tsgm);
+
+ // Now try with a different size
+ FileSystemUtils.writeContentAsLatin1(out1.getPath(), "hallo2");
+ checkActionDirtiedByFile(out1, actionKey1, batchStatter, tsgm);
+ }
+
+ private void pretendBuildTwoArtifacts(
+ Artifact out1,
+ SkyKey actionKey1,
+ Artifact out2,
+ SkyKey actionKey2,
+ BatchStat batchStatter,
+ TimestampGranularityMonitor tsgm)
+ throws InterruptedException {
+ EvaluationContext evaluationContext =
+ EvaluationContext.newBuilder()
+ .setKeepGoing(false)
+ .setNumThreads(1)
+ .setEventHander(NullEventHandler.INSTANCE)
+ .build();
+
+ tsgm.setCommandStartTime();
differencer.inject(
ImmutableMap.<SkyKey, SkyValue>of(
actionKey1,
@@ -390,37 +421,45 @@
Runnables.doNothing(),
ImmutableSet.<Artifact>of(),
ImmutableSet.of(out2)))));
- EvaluationContext evaluationContext =
- EvaluationContext.newBuilder()
- .setKeepGoing(false)
- .setNumThreads(1)
- .setEventHander(NullEventHandler.INSTANCE)
- .build();
assertThat(driver.evaluate(ImmutableList.<SkyKey>of(), evaluationContext).hasError()).isFalse();
- assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(),
- batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).isEmpty();
-
- FileSystemUtils.writeContentAsLatin1(out1.getPath(), "goodbye");
assertThat(
- new FilesystemValueChecker(null, null)
+ new FilesystemValueChecker(tsgm, null)
.getDirtyActionValues(
evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED))
- .containsExactly(actionKey1);
+ .isEmpty();
+
+ tsgm.waitForTimestampGranularity(OutErr.SYSTEM_OUT_ERR);
+ }
+
+ private void checkActionDirtiedByFile(
+ Artifact file, SkyKey actionKey, BatchStat batchStatter, TimestampGranularityMonitor tsgm)
+ throws InterruptedException {
assertThat(
- new FilesystemValueChecker(null, null)
+ new FilesystemValueChecker(tsgm, null)
+ .getDirtyActionValues(
+ evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED))
+ .containsExactly(actionKey);
+ assertThat(
+ new FilesystemValueChecker(tsgm, null)
.getDirtyActionValues(
evaluator.getValues(),
batchStatter,
- new ModifiedFileSet.Builder().modify(out1.getExecPath()).build()))
- .containsExactly(actionKey1);
+ new ModifiedFileSet.Builder().modify(file.getExecPath()).build()))
+ .containsExactly(actionKey);
assertThat(
- new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(),
- batchStatter,
- new ModifiedFileSet.Builder().modify(
- out1.getExecPath().getParentDirectory()).build())).isEmpty();
+ new FilesystemValueChecker(tsgm, null)
+ .getDirtyActionValues(
+ evaluator.getValues(),
+ batchStatter,
+ new ModifiedFileSet.Builder()
+ .modify(file.getExecPath().getParentDirectory())
+ .build()))
+ .isEmpty();
assertThat(
- new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(),
- batchStatter, ModifiedFileSet.NOTHING_MODIFIED)).isEmpty();
+ new FilesystemValueChecker(tsgm, null)
+ .getDirtyActionValues(
+ evaluator.getValues(), batchStatter, ModifiedFileSet.NOTHING_MODIFIED))
+ .isEmpty();
}
private void checkDirtyTreeArtifactActions(BatchStat batchStatter) throws Exception {