test: add more tests (#1166)
* chore: reverse the order of stopping services * chore: reverse the order of stopping services * test: add more tests
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Func defines the method to calculate how long to retry.
|
||||
type Func func(attempt int) time.Duration
|
||||
|
||||
// LinearWithJitter waits a set period of time, allowing for jitter (fractional adjustment).
|
||||
|
||||
@@ -16,3 +16,15 @@ func TestExponential(t *testing.T) {
|
||||
fn := Exponential(time.Second)
|
||||
assert.EqualValues(t, time.Second, fn(1))
|
||||
}
|
||||
|
||||
func TestLinearWithJitter(t *testing.T) {
|
||||
const rounds = 1000000
|
||||
var total time.Duration
|
||||
fn := LinearWithJitter(time.Second, 0.5)
|
||||
for i := 0; i < rounds; i++ {
|
||||
total += fn(1)
|
||||
}
|
||||
|
||||
// 0.1% tolerance
|
||||
assert.True(t, total/time.Duration(rounds)-time.Second < time.Millisecond)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user