Skip to content

Commit

Permalink
Explicitly call rand.Seed() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik-K-N authored and Rajalakshmi-Girish committed Jan 12, 2023
1 parent e2093f8 commit 242b82c
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,17 @@ func TestJitterWithNegativeMaxFactor(t *testing.T) {
// jitter := duration + time.Duration(rand.Float64()*maxFactor*float64(duration))
// If maxFactor is 0.0 or less than 0.0, a suggested default value will be chosen.
// rand.Float64() returns, as a float64, a pseudo-random number in [0.0,1.0).
duration := time.Duration(time.Second)
duration := time.Second
maxFactor := -3.0
res := jitter(duration, maxFactor)
defaultMaxFactor := 1.0
expected := jitter(duration, defaultMaxFactor)
assert.Equal(t, expected-res >= time.Duration(0.0*float64(duration)), true)
assert.Equal(t, expected-res < time.Duration(1.0*float64(duration)), true)
// jitter with negative maxFactor should not be negative
assert.Equal(t, res >= duration, true)
assert.Equal(t, res <= 2*duration, true)

maxFactor = 2.0
res = jitter(duration, maxFactor)
assert.Equal(t, res >= duration, true)
assert.Equal(t, res <= 3*duration, true)
}

func TestDoExponentialBackoffRetry(t *testing.T) {
Expand Down

0 comments on commit 242b82c

Please sign in to comment.