fixing bugs - no longer panics when iteration < 0 or MaxIteration >= len(TheFibonacciSequence)-1
This commit is contained in:
@@ -50,8 +50,8 @@ func (f *FibonacciBackoff) Next() time.Duration {
|
||||
}
|
||||
|
||||
// increment f.Iteration if appropriate
|
||||
maxIteration := int64(len(TheFibonacciSequence) + 1)
|
||||
if f.MaxIteration > 0 {
|
||||
maxIteration := int64(len(TheFibonacciSequence) - 1)
|
||||
if f.MaxIteration > 0 && f.MaxIteration <= maxIteration {
|
||||
maxIteration = f.MaxIteration
|
||||
}
|
||||
if f.foundMax == 0 {
|
||||
|
||||
@@ -77,6 +77,20 @@ func TestFibonacciBackoffNextDoesNotOverflow(t *testing.T) {
|
||||
}
|
||||
previous = got
|
||||
}
|
||||
backoff.Reset()
|
||||
backoff.PauseMultiplier = time.Nanosecond
|
||||
for i := range len(TheFibonacciSequence) + 100 {
|
||||
var want time.Duration
|
||||
if i >= len(TheFibonacciSequence) {
|
||||
want = time.Duration(TheFibonacciSequence[len(TheFibonacciSequence)-1])
|
||||
} else {
|
||||
want = time.Duration(TheFibonacciSequence[i])
|
||||
}
|
||||
got := backoff.Next()
|
||||
if want != got {
|
||||
t.Fatalf("error: wanted %v; got %v\n", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFibonacciBackoffIterationLimit(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user