tests: 429 rate-limiting fix — polling 5s/8s/12s/20s, 429-backoff 5s/10s/20s/40s, rate limiter 15 calls/min

This commit is contained in:
Bernd (Hermes)
2026-07-30 19:12:28 +02:00
parent 5c22391287
commit 6aaadcdb88
3 changed files with 16 additions and 16 deletions
+10 -10
View File
@@ -24,13 +24,13 @@ from .rc_rest import RCRestClient
logger = logging.getLogger(__name__)
# Progressive backoff intervals in seconds (rate-limiter-friendly).
# Default: 2s -> 3s -> 5s -> 8s (max 18s total).
# Default: 5s -> 8s -> 12s -> 20s (max 45s total).
# Callers can override the first interval via initial_interval.
_DEFAULT_BACKOFF_INTERVALS = [2.0, 3.0, 5.0, 8.0]
_MAX_TOTAL_WAIT = 18.0 # seconds
_DEFAULT_BACKOFF_INTERVALS = [5.0, 8.0, 12.0, 20.0]
_MAX_TOTAL_WAIT = 45.0 # seconds
# 429 exponential backoff: 3s -> 6s -> 12s -> 20s -> 30s (max)
_MAX_429_BACKOFF = 30.0
# 429 exponential backoff: 5s -> 10s -> 20s -> 40s (max)
_MAX_429_BACKOFF = 40.0
# After 5 consecutive 429s, abort with SKIP instead of retrying forever
_MAX_CONSECUTIVE_429 = 5
@@ -89,7 +89,7 @@ def wait_for_bot_message(
cached_messages: list = [] # Cursor caching: reuse fetched batch
# Build backoff intervals with caller's initial_interval
backoff_intervals = [initial_interval, 3.0, 5.0, 8.0]
backoff_intervals = [initial_interval, 8.0, 12.0, 20.0]
while time.monotonic() < deadline:
# Cursor caching: if we already have messages, scan them first
@@ -137,8 +137,8 @@ def wait_for_bot_message(
"aggressive. Consider increasing poll intervals or "
"reducing concurrent test load."
)
# Exponential backoff on rate-limit errors: 3s -> 6s -> 12s -> 20s -> 30s
backoff = min(3.0 * (2 ** (consecutive_429 - 1)), _MAX_429_BACKOFF)
# Exponential backoff on rate-limit errors: 5s -> 10s -> 20s -> 40s
backoff = min(5.0 * (2 ** (consecutive_429 - 1)), _MAX_429_BACKOFF)
logger.warning(
"Poll: HTTP 429 (consecutive=%d/%d) -- backing off %ds",
consecutive_429, _MAX_CONSECUTIVE_429, backoff,
@@ -170,12 +170,12 @@ def wait_for_bot_message(
)
return msg
# Progressive backoff: initial_interval -> 3s -> 5s -> 8s
# Progressive backoff: initial_interval -> 8s -> 12s -> 20s
if interval_idx < len(backoff_intervals):
delay = backoff_intervals[interval_idx]
interval_idx += 1
else:
delay = 8.0
delay = 20.0
remaining = deadline - time.monotonic()
if remaining <= 0:
+3 -3
View File
@@ -77,9 +77,9 @@ class RCRestClient:
req = urllib.request.Request(url, data=body, headers=headers, method=method)
# 429 retry with exponential backoff: 3s → 6s → 12s → 20s → 30s (max 5 retries)
# Total possible wait: 71s — gives RC enough time to reset its rate-limit window.
_429_BACKOFFS = [3.0, 6.0, 12.0, 20.0, 30.0]
# 429 retry with exponential backoff: 5s → 10s → 20s → 40s (max 4 retries)
# Total possible wait: 75s — gives RC enough time to reset its rate-limit window.
_429_BACKOFFS = [5.0, 10.0, 20.0, 40.0]
max_429_retries = len(_429_BACKOFFS)
for attempt in range(max_429_retries + 1):
# Rate-limit before every API call (protects post, history, delete, etc.)