File tree 2 files changed +6
-4
lines changed
2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -115,11 +115,13 @@ func (b *ExponentialBackOff) Reset() {
115
115
// Randomized interval = RetryInterval * (1 ± RandomizationFactor)
116
116
func (b * ExponentialBackOff ) NextBackOff () time.Duration {
117
117
// Make sure we have not gone over the maximum elapsed time.
118
- if b .MaxElapsedTime != 0 && b .GetElapsedTime () > b .MaxElapsedTime {
118
+ elapsed := b .GetElapsedTime ()
119
+ next := getRandomValueFromInterval (b .RandomizationFactor , rand .Float64 (), b .currentInterval )
120
+ b .incrementCurrentInterval ()
121
+ if b .MaxElapsedTime != 0 && elapsed + next > b .MaxElapsedTime {
119
122
return b .Stop
120
123
}
121
- defer b .incrementCurrentInterval ()
122
- return getRandomValueFromInterval (b .RandomizationFactor , rand .Float64 (), b .currentInterval )
124
+ return next
123
125
}
124
126
125
127
// GetElapsedTime returns the elapsed time since an ExponentialBackOff instance
Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ func TestBackOffOverflow(t *testing.T) {
108
108
exp .Reset ()
109
109
110
110
exp .NextBackOff ()
111
- // Assert that when an overflow is possible the current varerval time.Duration is set to the max varerval time.Duration .
111
+ // Assert that when an overflow is possible, the current varerval time.Duration is set to the max varerval time.Duration.
112
112
assertEquals (t , testMaxInterval , exp .currentInterval )
113
113
}
114
114
You can’t perform that action at this time.
0 commit comments