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

Function test_lock_release_on_process_termination

tests/sqlite/test_lock.py:210–232  ·  view source on GitHub ↗
(lock_file: str, mode: Literal["read", "write"])

Source from the content-addressed store, hash-verified

208)
209@pytest.mark.timeout(PROCESS_DEADLINE * 4)
210def test_lock_release_on_process_termination(lock_file: str, mode: Literal["read", "write"]) -> None:
211 lock_acquired = Event()
212
213 crashing = Process(target=acquire_lock_and_crash, args=(lock_file, mode, lock_acquired))
214 crashing.start()
215
216 assert lock_acquired.wait(timeout=PROCESS_DEADLINE), "Lock not acquired by first process"
217
218 write_acquired = Event()
219 successor = Process(target=acquire_lock, args=(lock_file, "write", write_acquired))
220
221 # Reap the child before the test runner reports its own timeout.
222 reap_deadline: int = 5
223 with cleanup_processes([crashing, successor]):
224 crashing.terminate()
225 crashing.join(timeout=reap_deadline)
226
227 successor.start()
228
229 assert write_acquired.wait(timeout=PROCESS_DEADLINE), "Lock not acquired after process termination"
230
231 successor.join(timeout=PROCESS_DEADLINE)
232 assert not successor.is_alive(), "Successor did not exit cleanly"
233
234
235def acquire_lock_and_crash(lock_file: str, mode: Literal["read", "write"], acquired_event: EventType) -> None:

Callers

nothing calls this directly

Calls 3

cleanup_processesFunction · 0.90
waitMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected