forked from couchbase/gocb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queryretry_behaviour_test.go
53 lines (43 loc) · 1.84 KB
/
queryretry_behaviour_test.go
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
package gocb
import (
"testing"
"time"
)
func TestQueryDelayRetryBehaviorCanRetry(t *testing.T) {
behav := NewQueryDelayRetryBehavior(10, 1000, 1*time.Second, QueryLinearDelayFunction)
var retries uint
if !behav.CanRetry(retries) {
t.Log("TestQueryDelayRetryBehaviorLinear should have been able to retry but couldn't")
t.Fail()
}
retries = 9
if !behav.CanRetry(retries) {
t.Log("TestQueryDelayRetryBehaviorLinear should have been able to retry but couldn't")
t.Fail()
}
retries = 10
if behav.CanRetry(retries) {
t.Log("TestQueryDelayRetryBehaviorLinear shouldn't have been able to retry but could")
t.Fail()
}
}
func TestQueryDelayRetryBehaviorLinear(t *testing.T) {
behav := NewQueryDelayRetryBehavior(10, 2, 500*time.Millisecond, QueryLinearDelayFunction)
testNextInterval(t, behav, 1, 2*time.Millisecond, "TestQueryDelayRetryBehaviorLinear")
testNextInterval(t, behav, 5, 10*time.Millisecond, "TestQueryDelayRetryBehaviorLinear")
testNextInterval(t, behav, 10, 20*time.Millisecond, "TestQueryDelayRetryBehaviorLinear")
testNextInterval(t, behav, 1000, 500*time.Millisecond, "TestQueryDelayRetryBehaviorLinear")
}
func TestQueryDelayRetryBehaviorExponential(t *testing.T) {
behav := NewQueryDelayRetryBehavior(10, 2, 500*time.Millisecond, QueryExponentialDelayFunction)
testNextInterval(t, behav, 1, 2*time.Millisecond, "TestQueryDelayRetryBehaviorExponential")
testNextInterval(t, behav, 5, 32*time.Millisecond, "TestQueryDelayRetryBehaviorExponential")
testNextInterval(t, behav, 10, 500*time.Millisecond, "TestQueryDelayRetryBehaviorExponential")
}
func testNextInterval(t *testing.T, behav *QueryDelayRetryBehavior, retries uint, expected time.Duration, testName string) {
interval := behav.NextInterval(retries)
if interval != expected {
t.Logf("%s expected interval of %v but was %v", testName, expected, interval)
t.Fail()
}
}