fix: address code review findings
This commit is contained in:
@@ -85,13 +85,18 @@ func TestCircuitBreakerOpenAfterFailures(t *testing.T) {
|
||||
t.Errorf("expected state open, got %v", cb.state)
|
||||
}
|
||||
|
||||
// Wait for timeout
|
||||
time.Sleep(31 * time.Second)
|
||||
// Test state transition to half-open by manually setting state and time
|
||||
cb.state = open
|
||||
cb.openSince = time.Now().Add(-31 * time.Second)
|
||||
|
||||
// Should transition to half-open/open after timeout - allow() should return true
|
||||
// Should transition to half-open after timeout - allow() should return true
|
||||
if !cb.allow() {
|
||||
t.Error("expected allow() to return true after timeout")
|
||||
}
|
||||
|
||||
if cb.state != halfOpen {
|
||||
t.Errorf("expected state halfOpen after timeout, got %v", cb.state)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCircuitBreakerRecordSuccess(t *testing.T) {
|
||||
@@ -199,19 +204,10 @@ func TestRetryExhaustion(t *testing.T) {
|
||||
jitter: false,
|
||||
}
|
||||
|
||||
// Simulate consecutive failures
|
||||
var lastErr error
|
||||
for attempt := 0; attempt <= cfg.maxRetries; attempt++ {
|
||||
// Simulate a non-retryable error that gets recorded as failure
|
||||
// In real code, isRetryableError would return false
|
||||
lastErr = fmt.Errorf("attempt %d failed", attempt)
|
||||
_ = lastErr // track last error
|
||||
}
|
||||
|
||||
// After maxRetries+1 attempts (0-indexed: 0 to maxRetries), we've done 3 attempts
|
||||
// with 2 retries (attempts 0->1, 1->2), the 3rd attempt (index 2) is the last
|
||||
if cfg.maxRetries+1 < 3 {
|
||||
t.Error("expected at least 3 attempts with maxRetries=2")
|
||||
// Verify maxRetries=2 means 3 total attempts (0, 1, 2)
|
||||
totalAttempts := cfg.maxRetries + 1
|
||||
if totalAttempts != 3 {
|
||||
t.Errorf("expected 3 total attempts with maxRetries=2, got %d", totalAttempts)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user