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

Function test_non_blocking_behavior

tests/sqlite/test_lock.py:139–159  ·  view source on GitHub ↗
(lock_file: str)

Source from the content-addressed store, hash-verified

137
138@pytest.mark.timeout(PROCESS_DEADLINE * 3)
139def test_non_blocking_behavior(lock_file: str) -> None:
140 write_acquired = Event()
141 release_write = Event()
142
143 writer = Process(target=acquire_lock, args=(lock_file, "write", write_acquired, release_write))
144
145 with cleanup_processes([writer]):
146 writer.start()
147 assert write_acquired.wait(timeout=PROCESS_DEADLINE), "Write lock not acquired"
148
149 start_time = time.perf_counter()
150
151 with pytest.raises(Timeout):
152 ReadWriteLock(lock_file).acquire_read(blocking=False)
153
154 elapsed = time.perf_counter() - start_time
155
156 assert elapsed < 0.1, f"Non-blocking took too long: {elapsed}s"
157
158 release_write.set()
159 writer.join(timeout=PROCESS_DEADLINE)
160
161
162@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected