Skip to content

Commit

Permalink
ENH: log (at debug) cases where file time stamp is in the future
Browse files Browse the repository at this point in the history
It might be able to provide explanation for a flaky test observed on debian
build systems etc: con#55
  • Loading branch information
yarikoptic committed Nov 18, 2024
1 parent 67e084c commit b1032ad
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/fscacher/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def from_stat(cls, s):
return cls(s.st_mtime_ns, s.st_ctime_ns, s.st_size, s.st_ino)

def modified_in_window(self, min_dtime):
return abs(time.time() - self.mtime_ns * 1e-9) < min_dtime
return abs(elapsed_since(self.mtime_ns * 1e-9)) < min_dtime

def to_tuple(self):
return tuple(self)
Expand All @@ -236,7 +236,7 @@ def modified_in_window(self, min_dtime):
if self.last_modified is None:
return False
else:
return abs(time.time() - self.last_modified * 1e-9) < min_dtime
return abs(elapsed_since(self.last_modified * 1e-9)) < min_dtime

def to_tuple(self):
if self.hash is None:
Expand All @@ -250,3 +250,13 @@ def xor_bytes(b1: bytes, b2: bytes) -> bytes:
i1 = int.from_bytes(b1, sys.byteorder)
i2 = int.from_bytes(b2, sys.byteorder)
return (i1 ^ i2).to_bytes(length, sys.byteorder)

def elapsed_since(t: float) -> float:
t_now = time.time()
dt = t_now - t
if dt < 0:
lgr.debug(
"Time is in the future: %f; now: %f; dt=%g",
t, t_now, dt
)
return dt

0 comments on commit b1032ad

Please sign in to comment.