Skip to content

Commit

Permalink
make sure no randomness is used when randomizationFactor is 0 (#118)
Browse files Browse the repository at this point in the history
in current implementation there is the following issue - it's not possible to disable randomization.
I'd expect that if I set randomizationFactor to 0, no randomness will be done.

I've updated the code accordingly to fix the issue.
  • Loading branch information
nirrozenbaum committed Nov 11, 2021
1 parent a78d380 commit 6b0e4ad
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions exponential.go
Expand Up @@ -147,6 +147,9 @@ func (b *ExponentialBackOff) incrementCurrentInterval() {
// Returns a random value from the following interval:
// [currentInterval - randomizationFactor * currentInterval, currentInterval + randomizationFactor * currentInterval].
func getRandomValueFromInterval(randomizationFactor, random float64, currentInterval time.Duration) time.Duration {
if randomizationFactor == 0 {
return currentInterval // make sure no randomness is used when randomizationFactor is 0.
}
var delta = randomizationFactor * float64(currentInterval)
var minInterval = float64(currentInterval) - delta
var maxInterval = float64(currentInterval) + delta
Expand Down

0 comments on commit 6b0e4ad

Please sign in to comment.