fix: extend polling budget for slow WorldQuant PnL
This commit is contained in:
@@ -265,3 +265,49 @@ async def test_concurrent_expiry_authenticates_once(settings):
|
||||
assert await asyncio.gather(client.profile(), client.profile()) == [{"id": "user"}, {"id": "user"}]
|
||||
assert auth_count == 2 # Initial connection plus one shared reauthentication.
|
||||
await client.close()
|
||||
|
||||
|
||||
async def test_slow_pnl_waits_beyond_network_retry_budget(settings):
|
||||
calls, delays = 0, []
|
||||
|
||||
async def sleep(delay):
|
||||
delays.append(delay)
|
||||
|
||||
def handler(request):
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
assert request.url.path == '/alphas/LL977PqL/recordsets/pnl'
|
||||
if calls <= 6:
|
||||
return httpx.Response(200, headers={'Retry-After': '1.0'})
|
||||
return httpx.Response(200, json={'records': []})
|
||||
|
||||
client = WqClient(settings, transport=httpx.MockTransport(handler), sleep=sleep)
|
||||
client.credentials, client.authenticated = ('test@example.com', 'secret'), True
|
||||
try:
|
||||
assert await client.pnl('LL977PqL') == {'records': []}
|
||||
assert calls == 7
|
||||
assert delays == [1.0] * 6
|
||||
finally:
|
||||
await client.close()
|
||||
|
||||
|
||||
async def test_pnl_polling_remains_bounded(settings):
|
||||
settings.pnl_poll_attempts = 5
|
||||
delays = []
|
||||
|
||||
async def sleep(delay):
|
||||
delays.append(delay)
|
||||
|
||||
client = WqClient(
|
||||
settings,
|
||||
transport=httpx.MockTransport(lambda r: httpx.Response(200, headers={'Retry-After': '1.0'})),
|
||||
sleep=sleep,
|
||||
)
|
||||
client.credentials, client.authenticated = ('test@example.com', 'secret'), True
|
||||
try:
|
||||
with pytest.raises(WqError) as error:
|
||||
await client.pnl('LL977PqL')
|
||||
assert error.value.code == 'pending'
|
||||
assert delays == [1.0] * 4
|
||||
finally:
|
||||
await client.close()
|
||||
|
||||
Reference in New Issue
Block a user