Skip to content

♻️ refactor(util): test helpers via public locks - #764

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:simp-util-docs
Oct 2, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:simp-util-docs

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

This follows up #762 with edits that missed its merge, and moves tests/test_util.py off the private filelock._util module. 🧹 Those tests called three private helpers and patched filelock._util.os.lstat, so a refactor inside the module could break them while every lock kept its behavior.

Each race starts from a dead holder's marker and runs through SoftFileLock. We patch Path.rename or os.lstat to play a peer that recreates or releases the marker mid-break, since those are the filesystem calls the break makes. Two guards in _util.py changed nothing a caller could observe. Every break_lock_file caller suppresses OSError, so the try around its re-check lstat goes; touch has one caller, which passes a descriptor each time, so fd becomes required.

No lock changes behavior. The break_lock_file docstring opens with the reason it renames before unlinking. Of several processes racing to break the same lock, the first to rename takes the file and the rest get OSError.

@gaborbernat gaborbernat added enhancement skip news Internal change; exempt from the news fragment check labels Oct 1, 2026
tests/test_util.py called three private helpers from filelock._util and
patched filelock._util.os.lstat. Drive the same races through
SoftFileLock, and patch the stdlib Path.rename and os.lstat to play a
peer.

Every break_lock_file caller suppresses OSError, so drop the guard
around the re-check lstat. touch has one caller. It passes a descriptor
each time, so make fd required and drop the path-based symlink test,
which reached a branch no caller takes where utime accepts a descriptor.

Open the break_lock_file docstring with why it renames first.

Claude-Session: https://claude.ai/code/session_0185Ga4wvPxDBm7NwTthKqYf
@gaborbernat
gaborbernat enabled auto-merge (squash) October 1, 2026 23:38
@gaborbernat
gaborbernat disabled auto-merge October 2, 2026 00:16
@gaborbernat
gaborbernat merged commit bc2405b into tox-dev:main Oct 2, 2026
46 checks passed
@gaborbernat
gaborbernat deleted the simp-util-docs branch October 3, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement skip news Internal change; exempt from the news fragment check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant