(lock_file: str, mode: Literal["read", "write"])
| 208 | ) |
| 209 | @pytest.mark.timeout(PROCESS_DEADLINE * 4) |
| 210 | def 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 | |
| 235 | def acquire_lock_and_crash(lock_file: str, mode: Literal["read", "write"], acquired_event: EventType) -> None: |
nothing calls this directly
no test coverage detected