1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
package backoff
import (
"math/rand"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestOptionPassing(t *testing.T) {
cOptions := []ControllerOption{
WithMaxRetries(9999999999999),
}
igOptions := []ExponentialOption{
WithJitterFactor(0.99),
WithMaxInterval(24 * time.Hour),
WithMinInterval(time.Nanosecond),
WithMultiplier(99999),
WithRNG(rand.New(rand.NewSource(time.Now().UnixNano()))),
}
merged := igOptions
for _, option := range cOptions {
merged = append(merged, option.(ExponentialOption))
}
p := NewExponentialPolicy(merged...)
if !assert.Equal(t, cOptions, p.cOptions) {
return
}
if !assert.Equal(t, igOptions, p.igOptions) {
return
}
}
|