Skip to content

Commit 0196b9a

Browse files
committed
DialTimeout defaults back to 5 seconds
1 parent 8aecdb8 commit 0196b9a

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

hitless/circuit_breaker_test.go

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ func TestCircuitBreaker(t *testing.T) {
1818

1919
t.Run("InitialState", func(t *testing.T) {
2020
cb := newCircuitBreaker("test-endpoint:6379", config)
21-
21+
2222
if cb.IsOpen() {
2323
t.Error("Circuit breaker should start in closed state")
2424
}
25-
25+
2626
if cb.GetState() != CircuitBreakerClosed {
2727
t.Errorf("Expected state %v, got %v", CircuitBreakerClosed, cb.GetState())
2828
}
2929
})
3030

3131
t.Run("SuccessfulExecution", func(t *testing.T) {
3232
cb := newCircuitBreaker("test-endpoint:6379", config)
33-
33+
3434
err := cb.Execute(func() error {
3535
return nil // Success
3636
})
37-
37+
3838
if err != nil {
3939
t.Errorf("Expected no error, got %v", err)
4040
}
41-
41+
4242
if cb.GetState() != CircuitBreakerClosed {
4343
t.Errorf("Expected state %v, got %v", CircuitBreakerClosed, cb.GetState())
4444
}
@@ -77,18 +77,18 @@ func TestCircuitBreaker(t *testing.T) {
7777
t.Run("OpenCircuitFailsFast", func(t *testing.T) {
7878
cb := newCircuitBreaker("test-endpoint:6379", config)
7979
testError := errors.New("test error")
80-
80+
8181
// Force circuit to open
8282
for i := 0; i < 5; i++ {
8383
cb.Execute(func() error { return testError })
8484
}
85-
85+
8686
// Now it should fail fast
8787
err := cb.Execute(func() error {
8888
t.Error("Function should not be called when circuit is open")
8989
return nil
9090
})
91-
91+
9292
if err != ErrCircuitBreakerOpen {
9393
t.Errorf("Expected ErrCircuitBreakerOpen, got %v", err)
9494
}
@@ -103,30 +103,30 @@ func TestCircuitBreaker(t *testing.T) {
103103
}
104104
cb := newCircuitBreaker("test-endpoint:6379", testConfig)
105105
testError := errors.New("test error")
106-
106+
107107
// Force circuit to open
108108
for i := 0; i < 5; i++ {
109109
cb.Execute(func() error { return testError })
110110
}
111-
111+
112112
if cb.GetState() != CircuitBreakerOpen {
113113
t.Error("Circuit should be open")
114114
}
115-
115+
116116
// Wait for reset timeout
117117
time.Sleep(150 * time.Millisecond)
118-
118+
119119
// Next call should transition to half-open
120120
executed := false
121121
err := cb.Execute(func() error {
122122
executed = true
123123
return nil // Success
124124
})
125-
125+
126126
if err != nil {
127127
t.Errorf("Expected no error, got %v", err)
128128
}
129-
129+
130130
if !executed {
131131
t.Error("Function should have been executed in half-open state")
132132
}
@@ -141,15 +141,15 @@ func TestCircuitBreaker(t *testing.T) {
141141
}
142142
cb := newCircuitBreaker("test-endpoint:6379", testConfig)
143143
testError := errors.New("test error")
144-
144+
145145
// Force circuit to open
146146
for i := 0; i < 5; i++ {
147147
cb.Execute(func() error { return testError })
148148
}
149-
149+
150150
// Wait for reset timeout
151151
time.Sleep(100 * time.Millisecond)
152-
152+
153153
// Execute successful requests in half-open state
154154
for i := 0; i < 3; i++ {
155155
err := cb.Execute(func() error {
@@ -159,7 +159,7 @@ func TestCircuitBreaker(t *testing.T) {
159159
t.Errorf("Expected no error on attempt %d, got %v", i+1, err)
160160
}
161161
}
162-
162+
163163
// Circuit should now be closed
164164
if cb.GetState() != CircuitBreakerClosed {
165165
t.Errorf("Expected state %v, got %v", CircuitBreakerClosed, cb.GetState())
@@ -175,24 +175,24 @@ func TestCircuitBreaker(t *testing.T) {
175175
}
176176
cb := newCircuitBreaker("test-endpoint:6379", testConfig)
177177
testError := errors.New("test error")
178-
178+
179179
// Force circuit to open
180180
for i := 0; i < 5; i++ {
181181
cb.Execute(func() error { return testError })
182182
}
183-
183+
184184
// Wait for reset timeout
185185
time.Sleep(100 * time.Millisecond)
186-
186+
187187
// First request in half-open state fails
188188
err := cb.Execute(func() error {
189189
return testError
190190
})
191-
191+
192192
if err != testError {
193193
t.Errorf("Expected test error, got %v", err)
194194
}
195-
195+
196196
// Circuit should be open again
197197
if cb.GetState() != CircuitBreakerOpen {
198198
t.Errorf("Expected state %v, got %v", CircuitBreakerOpen, cb.GetState())
@@ -204,8 +204,8 @@ func TestCircuitBreaker(t *testing.T) {
204204
testError := errors.New("test error")
205205

206206
// Execute some operations
207-
cb.Execute(func() error { return testError }) // Failure
208-
cb.Execute(func() error { return testError }) // Failure
207+
cb.Execute(func() error { return testError }) // Failure
208+
cb.Execute(func() error { return testError }) // Failure
209209

210210
stats := cb.GetStats()
211211

@@ -241,43 +241,43 @@ func TestCircuitBreakerManager(t *testing.T) {
241241

242242
t.Run("GetCircuitBreaker", func(t *testing.T) {
243243
manager := newCircuitBreakerManager(config)
244-
244+
245245
cb1 := manager.GetCircuitBreaker("endpoint1:6379")
246246
cb2 := manager.GetCircuitBreaker("endpoint2:6379")
247247
cb3 := manager.GetCircuitBreaker("endpoint1:6379") // Same as cb1
248-
248+
249249
if cb1 == cb2 {
250250
t.Error("Different endpoints should have different circuit breakers")
251251
}
252-
252+
253253
if cb1 != cb3 {
254254
t.Error("Same endpoint should return the same circuit breaker")
255255
}
256256
})
257257

258258
t.Run("GetAllStats", func(t *testing.T) {
259259
manager := newCircuitBreakerManager(config)
260-
260+
261261
// Create circuit breakers for different endpoints
262262
cb1 := manager.GetCircuitBreaker("endpoint1:6379")
263263
cb2 := manager.GetCircuitBreaker("endpoint2:6379")
264-
264+
265265
// Execute some operations
266266
cb1.Execute(func() error { return nil })
267267
cb2.Execute(func() error { return errors.New("test error") })
268-
268+
269269
stats := manager.GetAllStats()
270-
270+
271271
if len(stats) != 2 {
272272
t.Errorf("Expected 2 circuit breaker stats, got %d", len(stats))
273273
}
274-
274+
275275
// Check that we have stats for both endpoints
276276
endpoints := make(map[string]bool)
277277
for _, stat := range stats {
278278
endpoints[stat.Endpoint] = true
279279
}
280-
280+
281281
if !endpoints["endpoint1:6379"] || !endpoints["endpoint2:6379"] {
282282
t.Error("Missing stats for expected endpoints")
283283
}
@@ -286,25 +286,25 @@ func TestCircuitBreakerManager(t *testing.T) {
286286
t.Run("Reset", func(t *testing.T) {
287287
manager := newCircuitBreakerManager(config)
288288
testError := errors.New("test error")
289-
289+
290290
cb := manager.GetCircuitBreaker("test-endpoint:6379")
291-
291+
292292
// Force circuit to open
293293
for i := 0; i < 5; i++ {
294294
cb.Execute(func() error { return testError })
295295
}
296-
296+
297297
if cb.GetState() != CircuitBreakerOpen {
298298
t.Error("Circuit should be open")
299299
}
300-
300+
301301
// Reset all circuit breakers
302302
manager.Reset()
303-
303+
304304
if cb.GetState() != CircuitBreakerClosed {
305305
t.Error("Circuit should be closed after reset")
306306
}
307-
307+
308308
if cb.failures.Load() != 0 {
309309
t.Error("Failure count should be reset to 0")
310310
}

hitless/config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func TestApplyDefaults(t *testing.T) {
171171
}
172172

173173
resultCapped := configWithLargeQueue.ApplyDefaultsWithPoolSize(20) // Small pool size
174-
expectedCap := 20 * 5 // 5x pool size = 100
174+
expectedCap := 20 * 5 // 5x pool size = 100
175175
if resultCapped.HandoffQueueSize != expectedCap {
176176
t.Errorf("Expected HandoffQueueSize to be capped by 5x pool size (%d), got %d", expectedCap, resultCapped.HandoffQueueSize)
177177
}
@@ -194,7 +194,7 @@ func TestApplyDefaults(t *testing.T) {
194194
}
195195

196196
resultVeryLarge := configWithVeryLargeQueue.ApplyDefaultsWithPoolSize(100) // Pool size 100
197-
expectedVeryLargeCap := 100 * 5 // 5x pool size = 500
197+
expectedVeryLargeCap := 100 * 5 // 5x pool size = 500
198198
if resultVeryLarge.HandoffQueueSize != expectedVeryLargeCap {
199199
t.Errorf("Expected very large HandoffQueueSize to be capped by 5x pool size (%d), got %d", expectedVeryLargeCap, resultVeryLarge.HandoffQueueSize)
200200
}
@@ -305,7 +305,7 @@ func TestIntegrationWithApplyDefaults(t *testing.T) {
305305
t.Run("ProcessorWithPartialConfigAppliesDefaults", func(t *testing.T) {
306306
// Create a partial config with only some fields set
307307
partialConfig := &Config{
308-
MaxWorkers: 15, // Custom value (>= 10 to test preservation)
308+
MaxWorkers: 15, // Custom value (>= 10 to test preservation)
309309
LogLevel: logging.LogLevelInfo, // Custom value
310310
// Other fields left as zero values - should get defaults
311311
}

internal/pool/pool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ func TestDialerRetryConfiguration(t *testing.T) {
454454
PoolSize: 1,
455455
PoolTimeout: time.Second,
456456
DialTimeout: time.Second,
457-
DialerRetries: 3, // Custom retry count
457+
DialerRetries: 3, // Custom retry count
458458
DialerRetryTimeout: 10 * time.Millisecond, // Fast retries for testing
459459
})
460460
defer connPool.Close()

options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ type Options struct {
109109

110110
// DialTimeout for establishing new connections.
111111
//
112-
// default: 10 seconds
112+
// default: 5 seconds
113113
DialTimeout time.Duration
114114

115115
// DialerRetries is the maximum number of retry attempts when dialing fails.
@@ -285,7 +285,7 @@ func (opt *Options) init() {
285285
opt.Protocol = 3
286286
}
287287
if opt.DialTimeout == 0 {
288-
opt.DialTimeout = 10 * time.Second
288+
opt.DialTimeout = 5 * time.Second
289289
}
290290
if opt.DialerRetries == 0 {
291291
opt.DialerRetries = 5

0 commit comments

Comments
 (0)