| 288 | @pytest.mark.timeout(60) |
| 289 | @pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock]) |
| 290 | def test_threaded_shared_lock_obj(lock_type: type[BaseFileLock], tmp_path: Path) -> None: |
| 291 | if sys.platform == "win32" and lock_type.__name__ == "SoftFileLock": # pragma: win32 cover |
| 292 | pytest.skip( |
| 293 | "SoftFileLock uses file-existence locking — on Windows, unlink can silently fail under heavy " |
| 294 | "thread contention (EACCES from antivirus/indexer), orphaning the lock file with no recovery path" |
| 295 | ) |
| 296 | |
| 297 | lock_path = tmp_path / "a" |
| 298 | lock = lock_type(str(lock_path)) |
| 299 | |
| 300 | def thread_work() -> None: |
| 301 | for _ in range(100): |
| 302 | with lock: |
| 303 | assert lock.is_locked |
| 304 | |
| 305 | threads = [ExThread(target=thread_work, name=f"t{i}") for i in range(100)] |
| 306 | for thread in threads: |
| 307 | thread.start() |
| 308 | for thread in threads: |
| 309 | thread.join() |
| 310 | |
| 311 | assert not lock.is_locked |
| 312 | |
| 313 | |
| 314 | @pytest.mark.timeout(60) |