Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_intl: resolve test flakiness by using integer nanosecond timestamps during file modification detection #11435

Merged
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Features added

Bugs fixed
----------
* #440: Fix coarse timestamp resolution in some filesystem generating a wrong
list of outdated files. (reverted)

Testing
--------
Expand Down
6 changes: 1 addition & 5 deletions sphinx/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,7 @@ def read_doc(self, docname: str, *, _cache: bool = True) -> None:
doctree = publisher.document

# store time of reading, for outdated files detection
# (Some filesystems have coarse timestamp resolution;
# therefore time.time() can be older than filesystem's timestamp.
# For example, FAT32 has 2sec timestamp resolution.)
self.env.all_docs[docname] = max(time.time(),
path.getmtime(self.env.doc2path(docname)))
self.env.all_docs[docname] = time.time_ns()

# cleanup
self.env.temp_data.clear()
Expand Down
10 changes: 5 additions & 5 deletions sphinx/environment/__init__.py
AA-Turner marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from collections import defaultdict
from copy import copy
from datetime import datetime
from os import path
from os import path, stat
from typing import TYPE_CHECKING, Any, Callable, Generator, Iterator

from docutils import nodes
Expand Down Expand Up @@ -481,12 +481,12 @@ def get_outdated_files(self, config_changed: bool) -> tuple[set[str], set[str],
continue
# check the mtime of the document
mtime = self.all_docs[docname]
newmtime = path.getmtime(self.doc2path(docname))
newmtime = stat(self.doc2path(docname)).st_mtime_ns
if newmtime > mtime:
logger.debug('[build target] outdated %r: %s -> %s',
docname,
datetime.utcfromtimestamp(mtime),
datetime.utcfromtimestamp(newmtime))
datetime.utcfromtimestamp(mtime / 1_000_000_000),
datetime.utcfromtimestamp(newmtime / 1_000_000_000))
changed.add(docname)
continue
# finally, check the mtime of dependencies
Expand All @@ -497,7 +497,7 @@ def get_outdated_files(self, config_changed: bool) -> tuple[set[str], set[str],
if not path.isfile(deppath):
changed.add(docname)
break
depmtime = path.getmtime(deppath)
depmtime = stat(deppath).st_mtime_ns
if depmtime > mtime:
changed.add(docname)
break
Expand Down