test(gateway): trust claimed readiness marker

This commit is contained in:
Xubin Ren
2026-08-17 20:56:10 +08:00
parent b52660760c
commit 6955d709d6
+9 -10
View File
@@ -103,19 +103,18 @@ def _foreground_child(
def _wait_for_claim( def _wait_for_claim(
runtime: GatewayRuntime,
process: subprocess.Popen[str], process: subprocess.Popen[str],
marker: Path, marker: Path,
) -> None: ) -> None:
deadline = time.monotonic() + 3 deadline = time.monotonic() + 3
while time.monotonic() < deadline and process.poll() is None: while time.monotonic() < deadline:
try: if marker.exists():
state = json.loads(runtime.paths.state_path.read_text(encoding="utf-8")) detail = marker.read_text(encoding="utf-8")
except (OSError, json.JSONDecodeError): if detail == "claimed":
time.sleep(0.01)
continue
if state.get("pid") == process.pid:
return return
pytest.fail(f"gateway claim failed: returncode={process.poll()}, {detail}")
if process.poll() is not None:
break
time.sleep(0.01) time.sleep(0.01)
detail = marker.read_text(encoding="utf-8") if marker.exists() else "no marker" detail = marker.read_text(encoding="utf-8") if marker.exists() else "no marker"
pytest.fail(f"gateway claim failed: returncode={process.poll()}, {detail}") pytest.fail(f"gateway claim failed: returncode={process.poll()}, {detail}")
@@ -287,7 +286,7 @@ def test_stop_allows_a_foreground_gateway_to_release_before_timeout(tmp_path):
marker = tmp_path / "foreground.marker" marker = tmp_path / "foreground.marker"
child = _foreground_child(tmp_path, 30, marker) child = _foreground_child(tmp_path, 30, marker)
try: try:
_wait_for_claim(runtime, child, marker) _wait_for_claim(child, marker)
result = runtime.stop(timeout_s=1) result = runtime.stop(timeout_s=1)
child.wait(timeout=3) child.wait(timeout=3)
@@ -306,7 +305,7 @@ def test_competing_foreground_claim_preserves_the_live_gateway(tmp_path):
first_marker = tmp_path / "first.marker" first_marker = tmp_path / "first.marker"
first = _foreground_child(tmp_path, 30, first_marker) first = _foreground_child(tmp_path, 30, first_marker)
try: try:
_wait_for_claim(runtime, first, first_marker) _wait_for_claim(first, first_marker)
second_marker = tmp_path / "second.marker" second_marker = tmp_path / "second.marker"
second = _foreground_child(tmp_path, 0, second_marker) second = _foreground_child(tmp_path, 0, second_marker)
try: try: