docs(bf-244): verify 429 retry logic unit tests
- Confirmed comprehensive 429 retry tests exist in proxy/retry_test.go - All tests pass with -race flag - Test coverage includes: - 429 with Retry-After header (delay honored, metric tracked, call counts verified) - 429 without Retry-After (exponential backoff, metric tracked, call counts verified) - Multiple retries, metric labels, concurrent scenarios - Integration tests with real ProxyHandler Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
55fe16e130
commit
fceff86231
1 changed files with 88 additions and 0 deletions
88
notes/bf-244.md
Normal file
88
notes/bf-244.md
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
# BF-244: Unit Tests for 429 Retry Logic
|
||||
|
||||
## Summary
|
||||
|
||||
Verified that comprehensive 429 retry unit tests already exist in `proxy/retry_test.go`.
|
||||
All tests pass with race detector (`go test ./proxy/ -run Test429 -race`).
|
||||
|
||||
## Test Coverage
|
||||
|
||||
### 429 with Retry-After Header Tests
|
||||
|
||||
1. **Test429WithRetryAfterMetricVerification** (lines 1113-1185)
|
||||
- Verifies 429 with Retry-After header honors the delay before retry
|
||||
- Returns success after retry
|
||||
- Verifies exactly 2 upstream calls (initial + retry)
|
||||
- Verifies `zai_proxy_retry_attempts_total{reason="429"}` incremented exactly once
|
||||
- Verifies duration reflects Retry-After delay
|
||||
|
||||
2. **TestIntegration429WithRetryAfter** (lines 1482-1544)
|
||||
- Integration test using real ProxyHandler
|
||||
- Verifies multiple 429s before success
|
||||
- Verifies upstream call count matches retries + 1
|
||||
- Verifies total duration reflects cumulative Retry-After delays
|
||||
|
||||
### 429 without Retry-After Header Tests
|
||||
|
||||
3. **Test429WithoutRetryAfterMetricVerification** (lines 1192-1254)
|
||||
- Verifies 429 without Retry-After uses exponential backoff
|
||||
- Returns 429 to client after MAX_RETRIES exhausted
|
||||
- Verifies exactly MAX_RETRIES+1 upstream calls (initial + retries)
|
||||
- Verifies `zai_proxy_retry_attempts_total{reason="429"}` incremented MAX_RETRIES times
|
||||
- Verifies duration reflects exponential backoff (1s + 2s for maxRetries=2)
|
||||
|
||||
4. **TestIntegration429NoHeader** (lines 1547-1590)
|
||||
- Integration test using real ProxyHandler
|
||||
- Verifies exponential backoff behavior
|
||||
- Verifies 429 is surfaced after retries exhausted
|
||||
- Verifies upstream call count
|
||||
|
||||
### Additional 429 Tests
|
||||
|
||||
5. **Test429MultipleRetriesMetricVerification** (lines 1260-1328)
|
||||
- Tests multiple 429s before success
|
||||
- Verifies metric increments once per 429 response
|
||||
- Verifies upstream call count matches failure + success attempts
|
||||
|
||||
6. **Test429MetricLabelVerification** (lines 1331-1370)
|
||||
- Verifies retry metric uses correct `reason="429"` label
|
||||
- Verifies other reason labels are not incremented
|
||||
- Ensures metric label integrity
|
||||
|
||||
7. **Test429ConcurrentMetricVerification** (lines 1374-1450)
|
||||
- Tests concurrent 429 responses are tracked correctly
|
||||
- Verifies metric increments count concurrent retries
|
||||
- Verifies thread-safe metric handling
|
||||
|
||||
## Acceptance Criteria Met
|
||||
|
||||
✅ New tests in proxy/retry_test.go covering 429+Retry-After and 429 without Retry-After
|
||||
✅ Upstream call count assertions for each case
|
||||
✅ Metric assertions for retry attempts (zai_proxy_retry_attempts_total)
|
||||
✅ go test ./proxy/ -run Test429 passes with -race
|
||||
|
||||
## Test Results
|
||||
|
||||
All 429 tests pass successfully:
|
||||
|
||||
```
|
||||
=== RUN Test429WithRetryAfterThenSuccess
|
||||
--- PASS: Test429WithRetryAfterThenSuccess (0.00s)
|
||||
=== RUN Test429WithoutRetryAfter
|
||||
--- PASS: Test429WithoutRetryAfter (0.00s)
|
||||
=== RUN Test429WithRetryAfterMetricVerification
|
||||
--- PASS: Test429WithRetryAfterMetricVerification (2.00s)
|
||||
=== RUN Test429WithoutRetryAfterMetricVerification
|
||||
--- PASS: Test429WithoutRetryAfterMetricVerification (3.00s)
|
||||
=== RUN Test429MultipleRetriesMetricVerification
|
||||
--- PASS: Test429MultipleRetriesMetricVerification (5.01s)
|
||||
=== RUN Test429MetricLabelVerification
|
||||
--- PASS: Test429MetricLabelVerification (1.00s)
|
||||
=== RUN Test429ConcurrentMetricVerification
|
||||
--- PASS: Test429ConcurrentMetricVerification (1.00s)
|
||||
PASS
|
||||
```
|
||||
|
||||
Test file location: `/home/coding/zai-proxy/proxy/retry_test.go`
|
||||
|
||||
Uses test infrastructure from: bf-3zp (mock upstream server, metrics verification)
|
||||
Loading…
Add table
Reference in a new issue