mirror of
https://github.com/coder/coder.git
synced 2026-09-21 20:51:01 +08:00
fix(aibridge): increase circuit breaker test timeout to prevent flake (#26519)
`TestCircuitBreaker_FullRecoveryCycle/OpenAI` flaked once on macOS CI. The most likely cause is that the circuit breaker `Timeout` (open-to-half-open transition) was too short relative to the time between test phases. On a slow runner, the breaker could transition to half-open before the test verified it was still open, so the request went through as a half-open probe instead of being rejected. Increases `Timeout` to `testutil.IntervalMedium` (250ms) across all circuit breaker integration tests. **Note:** Ideally, these tests would use a mock clock for deterministic timing, but https://github.com/sony/gobreaker (the library used for circuit breaker logic) uses real time internally and doesn't expose a clock interface. Closes https://linear.app/codercom/issue/AIGOV-438 > Generated with [Coder Agents](https://coder.com/agents) on behalf of @ssncferreira
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/coder/coder/v2/aibridge/internal/testutil"
|
||||
"github.com/coder/coder/v2/aibridge/metrics"
|
||||
"github.com/coder/coder/v2/aibridge/provider"
|
||||
"github.com/coder/coder/v2/testutil"
|
||||
)
|
||||
|
||||
// Common response bodies for circuit breaker tests.
|
||||
@@ -126,7 +127,7 @@ func TestCircuitBreaker_FullRecoveryCycle(t *testing.T) {
|
||||
cbConfig := &config.CircuitBreaker{
|
||||
FailureThreshold: 2,
|
||||
Interval: time.Minute,
|
||||
Timeout: 50 * time.Millisecond,
|
||||
Timeout: testutil.IntervalMedium,
|
||||
MaxRequests: 1,
|
||||
}
|
||||
|
||||
@@ -283,7 +284,7 @@ func TestCircuitBreaker_HalfOpenFailure(t *testing.T) {
|
||||
cbConfig := &config.CircuitBreaker{
|
||||
FailureThreshold: 2,
|
||||
Interval: time.Minute,
|
||||
Timeout: 50 * time.Millisecond,
|
||||
Timeout: testutil.IntervalMedium,
|
||||
MaxRequests: 1,
|
||||
}
|
||||
|
||||
@@ -431,7 +432,7 @@ func TestCircuitBreaker_HalfOpenMaxRequests(t *testing.T) {
|
||||
cbConfig := &config.CircuitBreaker{
|
||||
FailureThreshold: 2,
|
||||
Interval: time.Minute,
|
||||
Timeout: 50 * time.Millisecond,
|
||||
Timeout: testutil.IntervalMedium,
|
||||
MaxRequests: maxRequests, // Allow only 2 concurrent requests in half-open
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user