diff --git a/backoff.go b/backoff.go index dcec0d0c..494e5cbb 100644 --- a/backoff.go +++ b/backoff.go @@ -61,7 +61,7 @@ func (b *backoff) updateAndGet(id peer.ID) (time.Duration, error) { duration: time.Duration(0), attempts: 0, } - case h.attempts > b.maxAttempts: + case h.attempts >= b.maxAttempts: return 0, fmt.Errorf("peer %s has reached its maximum backoff attempts", id) case h.duration < MinBackoffDelay: diff --git a/backoff_test.go b/backoff_test.go index bd13530d..ebcd2120 100644 --- a/backoff_test.go +++ b/backoff_test.go @@ -52,8 +52,8 @@ func TestBackoff_Update(t *testing.T) { } // trying once more beyond the threshold, hence expecting exceeding threshold - if _, err := b.updateAndGet(id1); err != nil { - t.Fatalf("invalid exceeding threshold status: %s", err) + if _, err := b.updateAndGet(id1); err == nil { + t.Fatalf("expected an error for going beyond threshold but got a nil: %s", err) } got, err := b.updateAndGet(id2)