Commit graph

2 commits

Author SHA1 Message Date
jedarden
55fe16e130 test(bf-244): add comprehensive 429 retry logic unit tests
Add unit tests covering all 429 retry scenarios with proper backoff behavior:

- Test429WithRetryAfterMetricVerification: Verifies 429 with Retry-After header
  honours the delay before retry, returns success, makes exactly 2 upstream calls,
  and increments zai_proxy_retry_attempts_total{reason="429"} once

- Test429WithoutRetryAfterMetricVerification: Verifies 429 without Retry-After
  uses exponential backoff up to MAX_RETRIES, surfaces 429, makes MAX_RETRIES+1
  upstream calls, and increments metric MAX_RETRIES times

- Test429MultipleRetriesMetricVerification: Verifies multiple 429 retries with
  correct metric increments and upstream call counts

- Test429MetricLabelVerification: Verifies retry metric uses correct reason labels

- Test429ConcurrentMetricVerification: Verifies concurrent 429 responses are
  tracked correctly in metrics

- Integration tests: TestIntegration429WithRetryAfter, TestIntegration429NoHeader
  test retry behavior through real proxy handler

All tests pass with -race detector. Uses test infrastructure from bf-3zp.
2026-07-02 15:01:04 -04:00
jedarden
ee39121cd9 test(ratelimiter): make AdaptiveRateLimiter testable via window duration injection
Add NewAdaptiveRateLimiterWithWindow constructor for test-only refactor:
- Production code uses NewAdaptiveRateLimiter with default 30s window
- Tests can inject shorter durations (e.g., 100ms) for fast execution
- No behavior changes to production rate limiting logic

Acceptance criteria:
- NewAdaptiveRateLimiterWithWindow accepts configurable window duration
- Production callers continue using default 30s window
- Tests can inject millisecond-scale windows for fast iteration
- No changes to rate limiting logic or defaults

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-02 10:55:06 -04:00