Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cenkalti/backoff
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.0.1
Choose a base ref
...
head repository: cenkalti/backoff
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.0.2
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Apr 3, 2020

  1. Copy the full SHA
    18fe4ce View commit details
Showing with 6 additions and 4 deletions.
  1. +5 −3 exponential.go
  2. +1 −1 exponential_test.go
8 changes: 5 additions & 3 deletions exponential.go
Original file line number Diff line number Diff line change
@@ -115,11 +115,13 @@ func (b *ExponentialBackOff) Reset() {
// Randomized interval = RetryInterval * (1 ± RandomizationFactor)
func (b *ExponentialBackOff) NextBackOff() time.Duration {
// Make sure we have not gone over the maximum elapsed time.
if b.MaxElapsedTime != 0 && b.GetElapsedTime() > b.MaxElapsedTime {
elapsed := b.GetElapsedTime()
next := getRandomValueFromInterval(b.RandomizationFactor, rand.Float64(), b.currentInterval)
b.incrementCurrentInterval()
if b.MaxElapsedTime != 0 && elapsed+next > b.MaxElapsedTime {
return b.Stop
}
defer b.incrementCurrentInterval()
return getRandomValueFromInterval(b.RandomizationFactor, rand.Float64(), b.currentInterval)
return next
}

// GetElapsedTime returns the elapsed time since an ExponentialBackOff instance
2 changes: 1 addition & 1 deletion exponential_test.go
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ func TestBackOffOverflow(t *testing.T) {
exp.Reset()

exp.NextBackOff()
// Assert that when an overflow is possible the current varerval time.Duration is set to the max varerval time.Duration .
// Assert that when an overflow is possible, the current varerval time.Duration is set to the max varerval time.Duration.
assertEquals(t, testMaxInterval, exp.currentInterval)
}