| 240 | |
| 241 | @pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock]) |
| 242 | def test_threaded_shared_lock_obj(lock_type: type[BaseFileLock], tmp_path: Path) -> None: |
| 243 | # Runs 100 threads, which need the filelock. The lock must be acquired if at least one thread required it and |
| 244 | # released, as soon as all threads stopped. |
| 245 | lock_path = tmp_path / "a" |
| 246 | lock = lock_type(str(lock_path)) |
| 247 | |
| 248 | def thread_work() -> None: |
| 249 | for _ in range(100): |
| 250 | with lock: |
| 251 | assert lock.is_locked |
| 252 | |
| 253 | threads = [ExThread(target=thread_work, name=f"t{i}") for i in range(100)] |
| 254 | for thread in threads: |
| 255 | thread.start() |
| 256 | for thread in threads: |
| 257 | thread.join() |
| 258 | |
| 259 | assert not lock.is_locked |
| 260 | |
| 261 | |
| 262 | @pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock]) |