test(gateway): make concurrency check deterministic

This commit is contained in:
Xubin Ren
2026-08-17 20:56:10 +08:00
parent 8eb2742c9b
commit 301d039fbb
+12 -4
View File
@@ -214,7 +214,7 @@ def test_concurrent_background_starts_create_only_one_process(tmp_path, monkeypa
return FakeProcess() return FakeProcess()
def first_sleep(_seconds): def first_sleep(_seconds):
assert release_first.wait(timeout=2) release_first.wait()
first = GatewayRuntime( first = GatewayRuntime(
paths=_paths(tmp_path), paths=_paths(tmp_path),
@@ -240,12 +240,20 @@ def test_concurrent_background_starts_create_only_one_process(tmp_path, monkeypa
target=lambda: results.append(second.start_background(GatewayStartOptions(port=18790))) target=lambda: results.append(second.start_background(GatewayStartOptions(port=18790)))
) )
second_started = False
first_thread.start() first_thread.start()
assert first_spawned.wait(timeout=2) try:
assert first_spawned.wait(timeout=10)
second_thread.start() second_thread.start()
second_started = True
finally:
release_first.set() release_first.set()
first_thread.join(timeout=2) first_thread.join(timeout=10)
second_thread.join(timeout=2) if second_started:
second_thread.join(timeout=10)
assert not first_thread.is_alive()
assert not second_thread.is_alive()
assert len(calls) == 1 assert len(calls) == 1
assert sorted((result.ok, result.message) for result in results) == [ assert sorted((result.ok, result.message) for result in results) == [