From b0b698c64366124aa0b656e1dba70da056b32c66 Mon Sep 17 00:00:00 2001 From: Susana Ferreira Date: Fri, 19 Jun 2026 09:23:57 +0100 Subject: [PATCH] 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 --- .../integrationtest/circuit_breaker_internal_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/aibridge/internal/integrationtest/circuit_breaker_internal_test.go b/aibridge/internal/integrationtest/circuit_breaker_internal_test.go index 1f5ddd71f3..990382c73e 100644 --- a/aibridge/internal/integrationtest/circuit_breaker_internal_test.go +++ b/aibridge/internal/integrationtest/circuit_breaker_internal_test.go @@ -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 }