Test that non-blocking parameter works correctly. This test directly attempts to acquire a read lock in non-blocking mode when a write lock is already held by another process.
(lock_file: str)
| 338 | |
| 339 | @pytest.mark.timeout(10) |
| 340 | def test_non_blocking_behavior(lock_file: str) -> None: |
| 341 | """Test that non-blocking parameter works correctly. |
| 342 | |
| 343 | This test directly attempts to acquire a read lock in non-blocking mode when a write lock is already held by another |
| 344 | process. |
| 345 | |
| 346 | """ |
| 347 | write_acquired = Event() |
| 348 | release_write = Event() |
| 349 | |
| 350 | writer = Process(target=acquire_lock, args=(lock_file, "write", write_acquired, release_write)) |
| 351 | |
| 352 | with cleanup_processes([writer]): |
| 353 | writer.start() |
| 354 | assert write_acquired.wait(timeout=2), "Write lock not acquired" |
| 355 | |
| 356 | lock = ReadWriteLock(lock_file) |
| 357 | |
| 358 | start_time = time.time() |
| 359 | |
| 360 | with pytest.raises(Timeout): |
| 361 | lock.acquire_read(blocking=False) |
| 362 | |
| 363 | elapsed = time.time() - start_time |
| 364 | |
| 365 | assert elapsed < 0.1, f"Non-blocking took too long: {elapsed}s" |
| 366 | |
| 367 | release_write.set() |
| 368 | writer.join(timeout=2) |
| 369 | |
| 370 | |
| 371 | def recursive_read_lock(lock_file: str, success_flag: Synchronized[int]) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…