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

Function test_non_blocking_behavior

tests/test_read_write.py:268–288  ·  view source on GitHub ↗
(lock_file: str)

Source from the content-addressed store, hash-verified

266
267@pytest.mark.timeout(_PROCESS_DEADLINE * 3)
268def test_non_blocking_behavior(lock_file: str) -> None:
269 write_acquired = Event()
270 release_write = Event()
271
272 writer = Process(target=acquire_lock, args=(lock_file, "write", write_acquired, release_write))
273
274 with cleanup_processes([writer]):
275 writer.start()
276 assert write_acquired.wait(timeout=_PROCESS_DEADLINE), "Write lock not acquired"
277
278 start_time = time.time()
279
280 with pytest.raises(Timeout):
281 ReadWriteLock(lock_file).acquire_read(blocking=False)
282
283 elapsed = time.time() - start_time
284
285 assert elapsed < 0.1, f"Non-blocking took too long: {elapsed}s"
286
287 release_write.set()
288 writer.join(timeout=_PROCESS_DEADLINE)
289
290
291@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 4

cleanup_processesFunction · 0.90
ReadWriteLockClass · 0.90
joinMethod · 0.80
acquire_readMethod · 0.45

Tested by

no test coverage detected