diff options
author | Miguel Alcon Pinto <malcon@google.com> | 2015-02-25 00:10:14 +0000 |
---|---|---|
committer | Han-Wen Nienhuys <hanwen@google.com> | 2015-02-25 00:10:14 +0000 |
commit | c5102fc5cec4336140889510a87ef1c57810911c (patch) | |
tree | 0107f147f39b941593883b7b6522ba6240470903 /src/test/java/com/google/devtools/build/lib/testutil/ManualClock.java | |
parent | f9e712aaf14541eaaef615fe6bcdd2b3025aca25 (diff) |
Compute action start time in critical path using Clock.currentTimeMillis instead of nanoTime. As nanoTime should only be used to compute time differences. To avoid having to pass two long values representing time (And calling twice to Clock.xxx methods per action executed) we compute the wall time by passing a clock and computing the difference from the start nano time.
--
MOS_MIGRATED_REVID=87102963
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/testutil/ManualClock.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/testutil/ManualClock.java | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/ManualClock.java b/src/test/java/com/google/devtools/build/lib/testutil/ManualClock.java index d4f6058169..de50bbdc68 100644 --- a/src/test/java/com/google/devtools/build/lib/testutil/ManualClock.java +++ b/src/test/java/com/google/devtools/build/lib/testutil/ManualClock.java @@ -29,9 +29,15 @@ public final class ManualClock implements Clock { return currentTimeMillis; } + /** + * Nano time should not be confused with wall time. Nano time is only mean to compute time + * differences. Because of this, we shift the time returned by 1000s, to test that the users + * of this class do not rely on nanoTime == currentTimeMillis. + */ @Override public long nanoTime() { - return TimeUnit.MILLISECONDS.toNanos(currentTimeMillis); + return TimeUnit.MILLISECONDS.toNanos(currentTimeMillis) + + TimeUnit.SECONDS.toNanos(1000); } public void advanceMillis(long time) { |