test: clean up concurrent cooldown processes

This commit is contained in:
ik
2026-09-11 07:56:01 +07:00
parent 8f76f70409
commit 51728bf3f2
+21 -17
View File
@@ -137,24 +137,28 @@ def test_check_and_reserve_atomic_under_concurrent_access(tmp_path: Path) -> Non
import multiprocessing
state_file = tmp_path / "concurrent.json"
results = multiprocessing.Manager().list()
# Explicitly shut down the manager and never leak a timed-out child.
with multiprocessing.Manager() as manager:
results = manager.list()
processes = []
for i in range(3):
args = (i, str(state_file), results)
p = multiprocessing.Process(target=_try_reserve_for_test, args=(args,))
processes.append(p)
for p in processes:
p.start()
for p in processes:
p.join(timeout=10)
for p in processes:
if p.is_alive():
p.terminate()
p.join(timeout=2)
# Launch 3 processes simultaneously
processes = []
for i in range(3):
args = (i, str(state_file), results)
p = multiprocessing.Process(target=_try_reserve_for_test, args=(args,))
processes.append(p)
for p in processes:
p.start()
for p in processes:
p.join(timeout=10)
# At most one should succeed
ok_count = sum(1 for _, r in results if r == "ok")
assert ok_count == 1, f"Expected exactly 1 ok, got {ok_count}: {results}"
denied_count = sum(1 for _, r in results if "cooldown" in r)
assert denied_count == 2, f"Expected 2 denied, got {denied_count}: {results}"
# At most one should succeed
ok_count = sum(1 for _, r in results if r == "ok")
assert ok_count == 1, f"Expected exactly 1 ok, got {ok_count}: {results}"
denied_count = sum(1 for _, r in results if "cooldown" in r)
assert denied_count == 2, f"Expected 2 denied, got {denied_count}: {results}"
# A03: Manual redirect control tests