fix: retry transient Tencent quote failures
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user