fix: retry transient Tencent quote failures

This commit is contained in:
王鹏
2026-07-08 22:09:17 +08:00
parent f7ef52ef64
commit 1e8858ac04
2 changed files with 34 additions and 4 deletions

View File

@@ -74,3 +74,25 @@ def test_provider_wraps_fetch_errors():
with pytest.raises(QuoteFetchError, match="Tencent quote request failed"):
provider.fetch_quotes([Instrument(id=1, code="000001", name="平安银行")])
def test_provider_retries_once_after_transient_fetch_error():
raw = (
'v_sz000001="51~平安银行~000001~10.60~10.47~10.44~0~0~0~'
'0~0~0~0~0~0~0~0~0~0~0~0~0~0~0~0~0~0~0~0~~20260708161430~0.13~1.24~10.63~10.34";'
).encode("gbk")
calls = 0
def flaky_fetch(url: str, timeout: float) -> bytes:
nonlocal calls
calls += 1
if calls == 1:
raise OSError("bad gateway")
return raw
provider = TencentQuoteProvider(fetcher=flaky_fetch, retries=1)
quotes = provider.fetch_quotes([Instrument(id=1, code="000001", name="平安银行")])
assert calls == 2
assert quotes["000001"].price == Decimal("10.60")