@@ -13,26 +13,23 @@ import (
1313// TestCalculateBackoff tests the backoff calculation for various retry counts
1414func TestCalculateBackoff (t * testing.T ) {
1515 tests := []struct {
16- retry int
16+ retry int
17+ expectedMin time.Duration
18+ expectedMax time.Duration
1719 }{
18- {retry : 0 },
19- {retry : 1 },
20- {retry : 2 },
21- {retry : 5 }, // Test a higher number of retries to ensure maxDelay is respected
20+ {retry : 0 , expectedMin : baseDelay , expectedMax : maxDelay },
21+ {retry : 1 , expectedMin : baseDelay * 2 , expectedMax : maxDelay },
22+ {retry : 2 , expectedMin : baseDelay * 4 , expectedMax : maxDelay },
23+ {retry : 5 , expectedMin : baseDelay * 32 , expectedMax : maxDelay },
2224 }
2325
2426 for _ , tt := range tests {
2527 t .Run ("RetryCount" + strconv .Itoa (tt .retry ), func (t * testing.T ) {
26-
2728 delay := calculateBackoff (tt .retry )
2829
29- // The delay should never exceed maxDelay
30- assert .LessOrEqual (t , delay , maxDelay , "Delay should not exceed maxDelay" )
31-
32- // The delay for 0 retries should be at least baseDelay
33- if tt .retry == 0 {
34- assert .GreaterOrEqual (t , delay , baseDelay , "Delay for 0 retries should be at least baseDelay" )
35- }
30+ // The delay should be within the expected range
31+ assert .GreaterOrEqual (t , delay , tt .expectedMin , "Delay should be greater than or equal to expected minimum" )
32+ assert .LessOrEqual (t , delay , tt .expectedMax , "Delay should be less than or equal to expected maximum" )
3633 })
3734 }
3835}
0 commit comments