test(proxy): cross rate limit boundary deterministically

This commit is contained in:
Sisyphus 2026-08-30 16:23:03 +08:00
parent d15740e29b
commit 673e978682
2 changed files with 11 additions and 9 deletions

View file

@ -1126,9 +1126,13 @@ class _PROXY_MaxParallelRequestsHandler_v3(CustomLogger):
nx=True,
parent_otel_span=parent_otel_span,
)
current_window_value = legacy_window_value if inserted else await redis_cache.async_get_cache(
key=window_key,
parent_otel_span=parent_otel_span,
current_window_value = (
legacy_window_value
if inserted
else await redis_cache.async_get_cache(
key=window_key,
parent_otel_span=parent_otel_span,
)
)
if current_window_value is not None:
await self.internal_usage_cache.async_set_cache(
@ -1212,9 +1216,7 @@ class _PROXY_MaxParallelRequestsHandler_v3(CustomLogger):
# Only compute limit_remaining if current_limit is not None
limit_remaining = (
current_limit - int(effective_counter_value)
if effective_counter_value is not None
else current_limit
current_limit - int(effective_counter_value) if effective_counter_value is not None else current_limit
)
statuses.append(

View file

@ -6359,10 +6359,10 @@ async def test_over_limit_mirror_does_not_reject_after_window_roll(monkeypatch,
)
assert exc_info.value.status_code == 429
# After the window boundary (t=59.75, while the stale mirror entry is
# still cached) the key must recover immediately instead of being
# After the window boundary (strictly past 60s, while the stale mirror
# entry is still cached) the key must recover immediately instead of being
# rejected from the stale local mirror.
time_controller.advance(39.75)
time_controller.advance(40.25)
await parallel_request_handler.async_pre_call_hook(
user_api_key_dict=user_api_key_dict, cache=local_cache, data={}, call_type=""
)