From 79e80150c4cc85ad09a4ca1dd7fa7cb7b9e4e4e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Wed, 7 Oct 2026 22:59:01 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20test:=20drop=20timing=20races=20?= =?UTF-8?q?from=20two=20runner-load=20flakes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The strict reaper test asserted a 0.1 s wall-clock bound next to an unlink count of one; the count alone proves the reaper does not retry a sharing violation, and a loaded free-threaded Windows runner missed the bound on #803 and #797. The lease transient-error test let two refresh failures run against a 0.8 s compromise window; a slow Windows runner spent that window on two ticks and reported refresh-failed on #795. A 30 s lease keeps the test on the retry behaviour; the deadline keeps its own test. --- tests/test_soft_lease.py | 3 ++- tests/test_strict_soft_failures.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_soft_lease.py b/tests/test_soft_lease.py index 44af7ec4..9aa7e53d 100644 --- a/tests/test_soft_lease.py +++ b/tests/test_soft_lease.py @@ -217,7 +217,8 @@ def flaky(path: str, *args: object, **kwargs: object) -> object: mocker.patch(f"filelock._lease.{target}", side_effect=flaky) seen: list[LeaseCompromise] = [] - lease = _lease(marker, on_compromise=seen.append) + # A long lease keeps a slow runner's two failed ticks inside the window; the deadline has its own test above. + lease = _lease(marker, lease_duration=30, on_compromise=seen.append) with lease: time.sleep(_HEARTBEAT * 6) # several ticks: the first two fail, the rest recover assert seen == [] diff --git a/tests/test_strict_soft_failures.py b/tests/test_strict_soft_failures.py index 008c19e7..3aa9949a 100644 --- a/tests/test_strict_soft_failures.py +++ b/tests/test_strict_soft_failures.py @@ -494,11 +494,11 @@ def test_strict_soft_reaper_does_not_retry_sharing_error(tmp_path: Path, mocker: side_effect=PermissionError(EACCES, "sharing violation"), ) - started = time.perf_counter() + sleep = mocker.patch("filelock._strict.time.sleep") + assert StrictSoftFileLock(lock_path).claims == () - elapsed = time.perf_counter() - started reaper_unlinks = [call.args[0] for call in unlink.call_args_list].count(private_path) - assert (reaper_unlinks, elapsed < 0.1, private_path.exists()) == (1, True, True) + assert (reaper_unlinks, sleep.call_count, private_path.exists()) == (1, 0, True) @pytest.mark.parametrize("record", ["claim", "sentinel"])