From 0726e6c8b1ce6b8c792d9a2e1fb378f662d527fd Mon Sep 17 00:00:00 2001 From: Nir Rozenbaum Date: Thu, 11 Nov 2021 16:40:27 +0200 Subject: [PATCH] make sure no randomness is used when randomizationFactor is 0 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. --- exponential.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/exponential.go b/exponential.go index 3d34532..2c56c1e 100644 --- a/exponential.go +++ b/exponential.go @@ -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