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

Function test_timeout_behavior

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

Source from the content-addressed store, hash-verified

111
112@pytest.mark.timeout(PROCESS_DEADLINE * 3)
113def test_timeout_behavior(lock_file: str) -> None:
114 write_acquired = Event()
115 release_write = Event()
116 read_acquired = Event()
117
118 writer = Process(target=acquire_lock, args=(lock_file, "write", write_acquired, release_write))
119 reader = Process(target=acquire_lock, args=(lock_file, "read", read_acquired, None, 0.5, True))
120
121 with cleanup_processes([writer, reader]):
122 writer.start()
123 assert write_acquired.wait(timeout=PROCESS_DEADLINE), "Write lock not acquired"
124
125 start_time = time.perf_counter()
126 reader.start()
127
128 assert not read_acquired.wait(timeout=1), "Read lock should not be acquired"
129 reader.join(timeout=PROCESS_DEADLINE)
130
131 elapsed = time.perf_counter() - start_time
132 assert 0.4 <= elapsed <= 10.0, f"Timeout was not respected: {elapsed}s"
133
134 release_write.set()
135 writer.join(timeout=PROCESS_DEADLINE)
136
137
138@pytest.mark.timeout(PROCESS_DEADLINE * 3)

Callers

nothing calls this directly

Calls 3

cleanup_processesFunction · 0.90
waitMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected