From cf6c8a9c365c1d6795af00830cde19b7b506a490 Mon Sep 17 00:00:00 2001 From: Jesse_Chen Date: Fri, 4 Sep 2026 03:20:21 +0800 Subject: [PATCH] test(api): stabilize vedastro timeout coverage --- tests/test_api_server_security.py | 36 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/test_api_server_security.py b/tests/test_api_server_security.py index d9276e01..f86a962e 100644 --- a/tests/test_api_server_security.py +++ b/tests/test_api_server_security.py @@ -7,6 +7,7 @@ import base64 import json import os import sys +import threading import time from io import BytesIO from pathlib import Path @@ -2520,8 +2521,10 @@ def test_consultation_foreground_times_out_vedastro_without_failing_local(monkey 'themes': {}, }) + release_gateway = threading.Event() + def slow_gateway(body): - time.sleep(0.4) + release_gateway.wait(timeout=2) return { 'scope': 'vedastro_gateway_run', 'status': 'official_verified', @@ -2531,20 +2534,23 @@ def test_consultation_foreground_times_out_vedastro_without_failing_local(monkey monkeypatch.setattr(handler, '_compute_vedastro_gateway_run', slow_gateway) - result = handler._compute_consultation_workflow({ - 'entry_mode': 'direct_chart', - 'question': '应期与阶段问题:深入看今日', - 'theme': ['career'], - 'year': 1997, - 'month': 8, - 'day': 8, - 'hour': 5, - 'minute': 0, - 'lat': 36.420487, - 'lon': 114.209936, - 'tz': 8, - 'defer_optional_external_evidence': True, - }) + try: + result = handler._compute_consultation_workflow({ + 'entry_mode': 'direct_chart', + 'question': '应期与阶段问题:深入看今日', + 'theme': ['career'], + 'year': 1997, + 'month': 8, + 'day': 8, + 'hour': 5, + 'minute': 0, + 'lat': 36.420487, + 'lon': 114.209936, + 'tz': 8, + 'defer_optional_external_evidence': True, + }) + finally: + release_gateway.set() assert result['success'] is True assert result['vedastro_gateway']['official_closure_reason'] == 'foreground_optional_evidence_timeout'