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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
package retry
import "testing"
func TestAdaptiveMode_defaultOptions(t *testing.T) {
a := NewAdaptiveMode()
s, ok := a.retryer.(*Standard)
if !ok || s == nil {
t.Fatalf("expect nested retryer %T, got none", s)
}
if e, a := false, a.options.FailOnNoAttemptTokens; e != a {
t.Errorf("expect %v default fast fail, got %v", e, a)
}
if e, a := DefaultMaxAttempts, s.options.MaxAttempts; e != a {
t.Errorf("expect %v default max attempts, got %v", e, a)
}
}
func TestAdaptiveMode_customOptions(t *testing.T) {
a := NewAdaptiveMode(func(ao *AdaptiveModeOptions) {
ao.FailOnNoAttemptTokens = true
ao.StandardOptions = append(ao.StandardOptions, func(so *StandardOptions) {
so.MaxAttempts = 10
})
})
s, ok := a.retryer.(*Standard)
if !ok || s == nil {
t.Fatalf("expect nested retryer %T, got none", s)
}
if e, a := true, a.options.FailOnNoAttemptTokens; e != a {
t.Errorf("expect %v custom fast fail, got %v", e, a)
}
if e, a := 10, s.options.MaxAttempts; e != a {
t.Errorf("expect %v custom max attempts, got %v", e, a)
}
}
func TestAdaptiveMode_copyOptions(t *testing.T) {
origDefaultThrottles := DefaultThrottles
defer func() {
DefaultThrottles = origDefaultThrottles
}()
DefaultThrottles = append([]IsErrorThrottle{}, DefaultThrottles...)
a := NewAdaptiveMode(func(ao *AdaptiveModeOptions) {
ao.Throttles[0] = nil
})
if DefaultThrottles[0] == nil {
t.Errorf("expect no change to global var")
}
if a.options.Throttles[0] != nil {
t.Errorf("expect throttles to be changed")
}
}
|