rate-limiting feinschliff: 429-retry, API-call reduction, auto-route detection

AUFGABE 1 — test_03 API-calls reduzieren:
- Skip get_latest_timestamp on source room; use post_message's returned ts as cursor (saves 1 channels.history call)
- Source polling: initial_interval=5s (was 2s), timeout=30s (was 25s)
- Target polling: timeout=60s (was 25s), initial_interval=8s (was 2s)
- post_message() now returns (msg_id, ts) tuple — all call sites updated

AUFGABE 2 — 429-retry strategy verbessern:
- rc_rest.py: 5 retries with 3s/6s/12s/20s/30s backoff (was 3 retries 3s/6s/12s)
- polling.py: 5 consecutive 429s before RateLimitSkip (was 3)
- polling.py: 429 backoff max 30s (was 24s)

AUFGABE 3 — rate-limit-cooldown erhöhen:
- conftest.py: 20s between tests (was 15s)

AUFGABE 4 — test_03 auto-route robustness:
- Detect auto-route (wechseln/sehe dich/thema) vs button-move-request (kopieren/rüber/attachments)
- Auto-route: pytest.skip with reason, no button click, no target verification
- Button-request: proceed with existing button-click + target-verification flow
This commit is contained in:
Bernd (Hermes)
2026-07-28 18:34:07 +02:00
parent 57ebbc6d6b
commit aa37de3e6e
7 changed files with 106 additions and 52 deletions
+12 -7
View File
@@ -77,8 +77,10 @@ class RCRestClient:
req = urllib.request.Request(url, data=body, headers=headers, method=method)
# 429 retry with exponential backoff: 3s → 6s → 12s, max 3 retries
max_429_retries = 3
# 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]
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.)
if self.rate_limiter is not None:
@@ -89,7 +91,7 @@ class RCRestClient:
return json.loads(resp.read().decode("utf-8"))
except urllib.error.HTTPError as e:
if e.code == 429 and attempt < max_429_retries:
backoff = 3.0 * (2 ** attempt) # 3s, 6s, 12s
backoff = _429_BACKOFFS[attempt]
logger.warning(
"HTTP 429 on %s %s (attempt %d/%d) — backing off %ds",
method, endpoint, attempt + 1, max_429_retries + 1, backoff,
@@ -147,7 +149,7 @@ class RCRestClient:
"username": user.get("username", "unknown"),
}
def post_message(self, room_id: str, text: str) -> str:
def post_message(self, room_id: str, text: str) -> tuple[str, str]:
"""Post a message to a room.
Args:
@@ -155,7 +157,9 @@ class RCRestClient:
text: The message text.
Returns:
The message _id from the API response.
A tuple of (message_id, timestamp) from the API response.
The timestamp can be used as a cursor for subsequent polling,
avoiding an extra channels.history call.
Raises:
RCRestError: On API failure.
@@ -171,8 +175,9 @@ class RCRestClient:
)
msg = r.get("message", {})
msg_id = msg.get("_id", "")
logger.info("Posted message %s to room %s", msg_id[:12], room_id[:12])
return msg_id
ts = msg.get("ts", "")
logger.info("Posted message %s (ts=%s) to room %s", msg_id[:12], ts[:19], room_id[:12])
return msg_id, ts
def get_history(
self,