Skip to content

Commit 33dd183

Browse files
committed
ENH: log (at debug) cases where file time stamp is in the future
It might be able to provide explanation for a flaky test observed on debian build systems etc: con#55
1 parent fcd8232 commit 33dd183

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/fscacher/cache.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def from_stat(cls, s):
209209
return cls(s.st_mtime_ns, s.st_ctime_ns, s.st_size, s.st_ino)
210210

211211
def modified_in_window(self, min_dtime):
212-
return abs(time.time() - self.mtime_ns * 1e-9) < min_dtime
212+
return abs(time_after(self.mtime_ns * 1e-9)) < min_dtime
213213

214214
def to_tuple(self):
215215
return tuple(self)
@@ -236,7 +236,7 @@ def modified_in_window(self, min_dtime):
236236
if self.last_modified is None:
237237
return False
238238
else:
239-
return abs(time.time() - self.last_modified * 1e-9) < min_dtime
239+
return abs(time_after(self.last_modified * 1e-9)) < min_dtime
240240

241241
def to_tuple(self):
242242
if self.hash is None:
@@ -250,3 +250,13 @@ def xor_bytes(b1: bytes, b2: bytes) -> bytes:
250250
i1 = int.from_bytes(b1, sys.byteorder)
251251
i2 = int.from_bytes(b2, sys.byteorder)
252252
return (i1 ^ i2).to_bytes(length, sys.byteorder)
253+
254+
def time_after(t_later: float) -> float:
255+
t_now = time.time()
256+
dt = t_now - t_later
257+
if dt < 0:
258+
lgr.debug(
259+
"Time is in the future: %f; now: %f; dt=%g",
260+
t_later, t_now, dt
261+
)
262+
return dt

0 commit comments

Comments
 (0)