Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions cuda_core/tests/test_program_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,7 @@ def _failing_open(path, flags, *args, **kwargs):
assert not utime_calls, "os.utime must not run after os.open fails"


@pytest.mark.human_reviewed
def test_filestream_touch_atime_swallows_fstat_failure(tmp_path, monkeypatch):
"""The best-effort atime bump swallows an ``os.fstat`` failure after the fd
was opened: the read still returns the cached bytes, closes the fd, and
Expand Down Expand Up @@ -2171,10 +2172,21 @@ def _failing_fstat(fd):
raise OSError("fstat refused")

utime_calls = []
monkeypatch.setattr(_os, "open", _recording_open)
monkeypatch.setattr(_os, "close", _recording_close)
monkeypatch.setattr(_os, "fstat", _failing_fstat)
monkeypatch.setattr(_os, "utime", lambda *a, **k: utime_calls.append((a, k)))

# Patch os only as _file_stream sees it: pytest's own output capture also calls os.fstat.
class _PatchedOs:
open = staticmethod(_recording_open)
close = staticmethod(_recording_close)
fstat = staticmethod(_failing_fstat)

@staticmethod
def utime(*a, **k):
utime_calls.append((a, k))

def __getattr__(self, name):
return getattr(_os, name)

monkeypatch.setattr(_program_cache._file_stream, "os", _PatchedOs())

assert cache[b"k"] == b"v"
assert fstat_calls, "the atime bump should have attempted os.fstat"
Expand Down
Loading