aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2018-03-09 02:01:18 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-09 02:02:59 -0800
commit9dac6736d811895a23b976d0af461cefd09afcd1 (patch)
tree26a0003792c93898bfbad51cb712ef14bd42374e /src/test/java/com/google/devtools/build
parent2ee6dd262bcf5fd890e24d5f185616b8ab259608 (diff)
tests: fix flaky SkyframeAwareActionTest
Fix testCacheBypassingActionWithMtimeChangingInput in SkyframeAwareActionTest by ensuring that enough time elapses between file updates so their effects are observable on the file's ctime. Fixes https://github.com/bazelbuild/bazel/issues/4755 Closes #4787. PiperOrigin-RevId: 188458542
Diffstat (limited to 'src/test/java/com/google/devtools/build')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/SkyframeAwareActionTest.java28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeAwareActionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeAwareActionTest.java
index bc206657e6..e521a54f35 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeAwareActionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeAwareActionTest.java
@@ -334,19 +334,39 @@ public class SkyframeAwareActionTest extends TimestampBuilderTestCase {
}
}
+ /** Sanity check: ensure that a file's ctime was updated from an older value. */
+ private void checkCtimeUpdated(Path path, long oldCtime) throws IOException {
+ if (oldCtime >= path.stat().getLastChangeTime()) {
+ throw new IllegalStateException(String.format("path=(%s), ctime=(%d)", path, oldCtime));
+ }
+ }
+
private void maybeChangeFile(Artifact file, ChangeArtifact changeRequest) throws Exception {
if (changeRequest == ChangeArtifact.DONT_CHANGE) {
return;
}
+ Path path = file.getPath();
+
if (changeRequest.changeMtime()) {
- // 1000000 should be larger than the filesystem timestamp granularity.
- file.getPath().setLastModifiedTime(file.getPath().getLastModifiedTime() + 1000000);
- tsgm.waitForTimestampGranularity(reporter.getOutErr());
+ long ctime = path.stat().getLastChangeTime();
+ // Ensure enough time elapsed for file updates to have a visible effect on the file's ctime.
+ tsgm.waitForTimestampGranularity(ctime, reporter.getOutErr());
+ // waitForTimestampGranularity waits long enough for System.currentTimeMillis() to be greater
+ // than the time at the setCommandStartTime() call. Therefore setting
+ // System.currentTimeMillis() is guaranteed to advance the file's ctime.
+ path.setLastModifiedTime(System.currentTimeMillis());
+ // Sanity check: ensure that updating the file's mtime indeed advanced its ctime.
+ checkCtimeUpdated(path, ctime);
}
if (changeRequest.changeContent()) {
- appendToFile(file.getPath());
+ long ctime = path.stat().getLastChangeTime();
+ // Ensure enough time elapsed for file updates to have a visible effect on the file's ctime.
+ tsgm.waitForTimestampGranularity(ctime, reporter.getOutErr());
+ appendToFile(path);
+ // Sanity check: ensure that appending to the file indeed advanced its ctime.
+ checkCtimeUpdated(path, ctime);
}
// Invalidate the file state value to inform Skyframe that the file may have changed.