MCPcopy Create free account
hub / github.com/tox-dev/filelock / test_non_blocking_behavior

Function test_non_blocking_behavior

tests/test_read_write.py:340–368  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

338
339@pytest.mark.timeout(10)
340def 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
371def recursive_read_lock(lock_file: str, success_flag: Synchronized[int]) -> None:

Callers

nothing calls this directly

Calls 4

acquire_readMethod · 0.95
ReadWriteLockClass · 0.90
cleanup_processesFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…