fixing bugs - no longer panics when iteration < 0 or MaxIteration >= len(TheFibonacciSequence)-1

This commit is contained in:
2026-02-26 16:28:19 -05:00
parent 69ca00b29d
commit b4edee4292
3 changed files with 24 additions and 2 deletions
+2 -2
View File
@@ -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 {
+14
View File
@@ -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) {