| 262 | @pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock]) |
| 263 | @pytest.mark.skipif(hasattr(sys, "pypy_version_info") and sys.platform == "win32", reason="deadlocks randomly") |
| 264 | def test_threaded_lock_different_lock_obj(lock_type: type[BaseFileLock], tmp_path: Path) -> None: |
| 265 | # Runs multiple threads, which acquire the same lock file with a different FileLock object. When thread group 1 |
| 266 | # acquired the lock, thread group 2 must not hold their lock. |
| 267 | |
| 268 | def t_1() -> None: |
| 269 | for _ in range(1000): |
| 270 | with lock_1: |
| 271 | assert lock_1.is_locked |
| 272 | assert not lock_2.is_locked |
| 273 | |
| 274 | def t_2() -> None: |
| 275 | for _ in range(1000): |
| 276 | with lock_2: |
| 277 | assert not lock_1.is_locked |
| 278 | assert lock_2.is_locked |
| 279 | |
| 280 | lock_path = tmp_path / "a" |
| 281 | lock_1, lock_2 = lock_type(str(lock_path)), lock_type(str(lock_path)) |
| 282 | threads = [(ExThread(t_1, f"t1_{i}"), ExThread(t_2, f"t2_{i}")) for i in range(10)] |
| 283 | |
| 284 | for thread_1, thread_2 in threads: |
| 285 | thread_1.start() |
| 286 | thread_2.start() |
| 287 | for thread_1, thread_2 in threads: |
| 288 | thread_1.join() |
| 289 | thread_2.join() |
| 290 | |
| 291 | assert not lock_1.is_locked |
| 292 | assert not lock_2.is_locked |
| 293 | |
| 294 | |
| 295 | @pytest.mark.parametrize("lock_type", [FileLock, SoftFileLock]) |