Visitar URL original
🧪 test: drop timing races from two runner-load flakes (#809) · tox-dev/filelock@cf092c7 · GitHub
Skip to content

Commit cf092c7

Browse files
authored
🧪 test: drop timing races from two runner-load flakes (#809)
1 parent 66d309d commit cf092c7

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎tests/test_soft_lease.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ def flaky(path: str, *args: object, **kwargs: object) -> object:
218218

219219
mocker.patch(f"filelock._lease.{target}", side_effect=flaky)
220220
seen: list[LeaseCompromise] = []
221-
lease = _lease(marker, on_compromise=seen.append)
221+
# A long lease keeps a slow runner's two failed ticks inside the window; the deadline has its own test above.
222+
lease = _lease(marker, lease_duration=30, on_compromise=seen.append)
222223
with lease:
223224
time.sleep(_HEARTBEAT * 6) # several ticks: the first two fail, the rest recover
224225
assert seen == []

‎tests/test_strict_soft_failures.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,11 @@ def test_strict_soft_reaper_does_not_retry_sharing_error(tmp_path: Path, mocker:
496496
side_effect=PermissionError(EACCES, "sharing violation"),
497497
)
498498

499-
started = time.perf_counter()
499+
sleep = mocker.patch("filelock._strict.time.sleep")
500+
500501
assert StrictSoftFileLock(lock_path).claims == ()
501-
elapsed = time.perf_counter() - started
502502
reaper_unlinks = [call.args[0] for call in unlink.call_args_list].count(private_path)
503-
assert (reaper_unlinks, elapsed < 0.1, private_path.exists()) == (1, True, True)
503+
assert (reaper_unlinks, sleep.call_count, private_path.exists()) == (1, 0, True)
504504

505505

506506
@pytest.mark.parametrize("record", ["claim", "sentinel"])

0 commit comments

Comments
 (0)