From 51728bf3f240f5e8b831abb0179305c5f5b4220d Mon Sep 17 00:00:00 2001 From: IK Date: Fri, 11 Sep 2026 07:56:01 +0700 Subject: [PATCH] test: clean up concurrent cooldown processes --- tests/test_community_cli.py | 38 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/tests/test_community_cli.py b/tests/test_community_cli.py index c085341..b681bba 100644 --- a/tests/test_community_cli.py +++ b/tests/test_community_cli.py @@ -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