test(gateway): isolate lifecycle lock behavior

This commit is contained in:
Xubin Ren
2026-08-17 20:56:10 +08:00
parent 78aa29ffc9
commit f5125f3c07
2 changed files with 9 additions and 5 deletions
+5
View File
@@ -206,6 +206,7 @@ def test_stop_reaps_an_owned_child_without_consuming_the_shutdown_timeout(
def test_concurrent_background_starts_create_only_one_process(tmp_path, monkeypatch):
first_spawned = threading.Event()
release_first = threading.Event()
lifecycle_lock = threading.Lock()
calls: list[list[str]] = []
def fake_popen(command, **_kwargs):
@@ -231,6 +232,10 @@ def test_concurrent_background_starts_create_only_one_process(tmp_path, monkeypa
for runtime in (first, second):
monkeypatch.setattr(runtime, "_is_pid_running", lambda _pid: True)
monkeypatch.setattr(runtime, "_process_identity", lambda _pid: 12345)
# Exercise the runtime's critical section without mixing an OS-level
# file lock into a same-process thread scheduling test. FileLock is
# independently responsible for cross-process portability.
monkeypatch.setattr(runtime, "_lifecycle_lock", lambda: lifecycle_lock)
results = []
first_thread = threading.Thread(