From 3055abcb56fe4b113122b067c4e02fe6ebe8520c Mon Sep 17 00:00:00 2001 From: Elie Bursztein Date: Sun, 27 Sep 2026 16:03:22 +0000 Subject: [PATCH] test(cache): stop the relatime emulation from refreshing atimes for real test_scanning_the_store_is_not_a_use_of_it failed intermittently on Linux (the orphan object was evicted along with the oldest generation). The _relatime helper stripped the native O_NOATIME flag before calling the real os.open, so the product's no-atime receipt read became an ordinary read on a real relatime mount (ext4, tmpfs): the kernel refreshed each receipt's 1972 atime to wall-clock time. Both generations then looked newer than the orphan, whose view receipt had been left at wall-clock time by the fixture, so the orphan went first -- whenever the scan landed in a later clock tick than the view write, and not otherwise. Pass the flag through where the platform has it, and pin the view receipt to the fixture's clock so any real refresh fails every run instead of racing the clock. Removing O_NOATIME from the product now fails the test deterministically. --- build_system/tests/cache/test_objectunits.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/build_system/tests/cache/test_objectunits.py b/build_system/tests/cache/test_objectunits.py index 1be406b14..fac9da50d 100644 --- a/build_system/tests/cache/test_objectunits.py +++ b/build_system/tests/cache/test_objectunits.py @@ -87,7 +87,13 @@ def store_with_three_generations(tmp_path: Path, paths: CachePaths): new = receipt(paths, "b", {"vmlinuz": new_kernel, "initrd": shared}, now) views = paths.stage("objects") / "receipts" / "views" / orphan.digest views.mkdir(parents=True) - (views / "package.deb.json").write_text("{}", encoding="utf-8") + filed = views / "package.deb.json" + filed.write_text("{}", encoding="utf-8") + # Every file in the store lives on the test's clock. A view left at wall-clock + # time made the orphan newer than any refreshed receipt only when the + # refresh landed in a later clock tick, which hid real atime refreshes + # behind a race instead of failing every time. + os.utime(filed, ns=(now - DAY_NS, now - DAY_NS)) return now, (old_kernel, new_kernel, shared, orphan), (old, new) @@ -138,8 +144,16 @@ def _relatime(monkeypatch: pytest.MonkeyPatch) -> None: The test above failed on the hosted Linux release lane and passed on macOS: the scan read each receipt to learn what it owns, the read marked it used, and the oldest generation came back looking newest. + + Where the platform has a real O_NOATIME the flag reaches the kernel + untouched. Stripping it there turned the emulation into a real read on a + real relatime mount: the kernel refreshed the receipt it had been asked + not to, to wall-clock time, and the test failed whenever that refresh + landed in a later clock tick than the fixture's last write. """ + native = hasattr(os, "O_NOATIME") noatime = getattr(os, "O_NOATIME", 0o1000000) + unknown_to_kernel = 0 if native else noatime monkeypatch.setattr(os, "O_NOATIME", noatime, raising=False) def touch(path: str | Path) -> None: @@ -149,7 +163,7 @@ def touch(path: str | Path) -> None: real_open, real_read_text = os.open, Path.read_text def open_(path, flags, *args, **kwargs): - descriptor = real_open(path, flags & ~noatime, *args, **kwargs) + descriptor = real_open(path, flags & ~unknown_to_kernel, *args, **kwargs) if not flags & noatime: touch(path) return descriptor