fix: 对齐规格解析跨端超时预算 (#257)

This commit is contained in:
chengma
2026-08-18 08:56:56 +08:00
parent 29cf66ce96
commit 6345b00106
7 changed files with 97 additions and 4 deletions
+5 -1
View File
@@ -26,6 +26,7 @@ from .task_models import TaskType
DEFAULT_ADMIN_BASE_URL = "https://buy.833729.com"
PURCHASE_SPEC_RESOLUTION_TIMEOUT_SECONDS = 60.0
class HttpAdminGateway(AdminGateway):
@@ -288,7 +289,10 @@ class HttpAdminGateway(AdminGateway):
method="POST",
)
try:
with self._opener(request, timeout=self._timeout_seconds) as response:
with self._opener(
request,
timeout=PURCHASE_SPEC_RESOLUTION_TIMEOUT_SECONDS,
) as response:
status = getattr(response, "status", None) or response.getcode()
body = response.read()
except HTTPError as exc:
+9 -2
View File
@@ -13,7 +13,11 @@ from src.admin_gateway import (
ClaimCapabilities,
ClientInfo,
)
from src.http_admin_gateway import DEFAULT_ADMIN_BASE_URL, HttpAdminGateway
from src.http_admin_gateway import (
DEFAULT_ADMIN_BASE_URL,
PURCHASE_SPEC_RESOLUTION_TIMEOUT_SECONDS,
HttpAdminGateway,
)
from src.task_models import TaskType
@@ -243,7 +247,10 @@ class HttpAdminGatewayTest(unittest.TestCase):
self.assertEqual(
headers["idempotency-key"], "spec-resolution-v1:key"
)
self.assertEqual(opener.timeout, 5)
self.assertEqual(
opener.timeout, PURCHASE_SPEC_RESOLUTION_TIMEOUT_SECONDS
)
self.assertEqual(PURCHASE_SPEC_RESOLUTION_TIMEOUT_SECONDS, 60.0)
def test_resolve_purchase_spec_accepts_all_nonmatched_business_outcomes(self):
for outcome in ("uncertain", "rejected", "failed"):
@@ -52,9 +52,11 @@ class _RecordingOpener:
def __init__(self, response):
self.response = response
self.request = None
self.timeout = None
def __call__(self, request, timeout):
self.request = request
self.timeout = timeout
if isinstance(self.response, Exception):
raise self.response
return self.response
@@ -279,6 +281,7 @@ class PurchaseSpecResolutionContractVectorTest(unittest.TestCase):
for name, value in opener.request.header_items()
}
self.assertEqual(headers["idempotency-key"], key)
self.assertEqual(opener.timeout, 60.0)
def test_error_vectors_are_identical_for_http_and_mock(self):
defaults = self.fixture["defaults"]