2019-06-22 02:13:33 -07:00
|
|
|
package xmpp
|
2019-06-06 02:58:50 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDurationForAttempt_NoJitter(t *testing.T) {
|
2019-06-22 02:13:33 -07:00
|
|
|
b := backoff{Base: 25, NoJitter: true}
|
2019-06-06 02:58:50 -07:00
|
|
|
bInMS := time.Duration(b.Base) * time.Millisecond
|
2019-06-22 02:13:33 -07:00
|
|
|
if b.durationForAttempt(0) != bInMS {
|
|
|
|
t.Errorf("incorrect default duration for attempt #0 (%d) = %d", b.durationForAttempt(0)/time.Millisecond, bInMS/time.Millisecond)
|
2019-06-06 02:58:50 -07:00
|
|
|
}
|
|
|
|
var prevDuration, d time.Duration
|
|
|
|
for i := 0; i < 10; i++ {
|
2019-06-22 02:13:33 -07:00
|
|
|
d = b.durationForAttempt(i)
|
2019-06-06 02:58:50 -07:00
|
|
|
if !(d >= prevDuration) {
|
|
|
|
t.Errorf("duration should be increasing between attempts. #%d (%d) > %d", i, d, prevDuration)
|
|
|
|
}
|
|
|
|
prevDuration = d
|
|
|
|
}
|
|
|
|
}
|