-
Notifications
You must be signed in to change notification settings - Fork 104
/
kvopmanager_test.go
153 lines (146 loc) · 6.09 KB
/
kvopmanager_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package gocb
import (
"testing"
"time"
)
func (suite *IntegrationTestSuite) TestKvOpManagerTimeouts() {
type tCase struct {
name string
timeout time.Duration
durabilityLevel DurabilityLevel
expectedDurabilityTimeout time.Duration
expectedDeadline time.Duration
}
testCases := []tCase{
{
name: "timeout",
timeout: 3000 * time.Millisecond,
expectedDurabilityTimeout: 0,
expectedDeadline: 3000 * time.Millisecond,
},
{
name: "timeout, with durability level majority",
timeout: 3000 * time.Millisecond,
durabilityLevel: DurabilityLevelMajority,
expectedDurabilityTimeout: time.Duration(float64(3000*time.Millisecond) * 0.9),
expectedDeadline: 3000 * time.Millisecond,
},
{
name: "timeout, with durability level persist to majority",
timeout: 3000 * time.Millisecond,
durabilityLevel: DurabilityLevelPersistToMajority,
expectedDurabilityTimeout: time.Duration(float64(3000*time.Millisecond) * 0.9),
expectedDeadline: 3000 * time.Millisecond,
},
{
name: "timeout, with durability level majority and persist master",
timeout: 3000 * time.Millisecond,
durabilityLevel: DurabilityLevelMajorityAndPersistOnMaster,
expectedDurabilityTimeout: time.Duration(float64(3000*time.Millisecond) * 0.9),
expectedDeadline: 3000 * time.Millisecond,
},
{
name: "low timeout",
timeout: 1000 * time.Millisecond,
expectedDurabilityTimeout: 0,
expectedDeadline: 1000 * time.Millisecond,
},
{
name: "low timeout, with durability level majority",
timeout: 1000 * time.Millisecond,
durabilityLevel: DurabilityLevelMajority,
expectedDurabilityTimeout: durabilityTimeoutFloor,
expectedDeadline: durabilityTimeoutFloor,
},
{
name: "low timeout, with durability level persist to majority",
timeout: 1000 * time.Millisecond,
durabilityLevel: DurabilityLevelPersistToMajority,
expectedDurabilityTimeout: durabilityTimeoutFloor,
expectedDeadline: durabilityTimeoutFloor,
},
{
name: "low timeout, with durability level majority and persist master",
timeout: 1000 * time.Millisecond,
durabilityLevel: DurabilityLevelMajorityAndPersistOnMaster,
expectedDurabilityTimeout: durabilityTimeoutFloor,
expectedDeadline: durabilityTimeoutFloor,
},
// Edge timeouts mean that the timeout set is above the durable floor but after applying the adaptive
// algorithm the value will be below and require coercion.
{
name: "edge timeout",
timeout: 1600 * time.Millisecond,
expectedDurabilityTimeout: 0,
expectedDeadline: 1600 * time.Millisecond,
},
{
name: "edge timeout, with durability level majority",
timeout: 1600 * time.Millisecond,
durabilityLevel: DurabilityLevelMajority,
expectedDurabilityTimeout: durabilityTimeoutFloor,
expectedDeadline: 1600 * time.Millisecond,
},
{
name: "edge timeout, with durability level persist to majority",
timeout: 1600 * time.Millisecond,
durabilityLevel: DurabilityLevelPersistToMajority,
expectedDurabilityTimeout: durabilityTimeoutFloor,
expectedDeadline: 1600 * time.Millisecond,
},
{
name: "edge timeout, with durability level majority and persist master",
timeout: 1600 * time.Millisecond,
durabilityLevel: DurabilityLevelMajorityAndPersistOnMaster,
expectedDurabilityTimeout: durabilityTimeoutFloor,
expectedDeadline: 1600 * time.Millisecond,
},
{
name: "no timeout",
timeout: globalCollection.timeoutsConfig.KVTimeout,
expectedDurabilityTimeout: 0,
expectedDeadline: globalCollection.timeoutsConfig.KVTimeout,
},
{
name: "no timeout, with durability level majority",
timeout: 0,
durabilityLevel: DurabilityLevelMajority,
expectedDurabilityTimeout: time.Duration(float64(globalCollection.timeoutsConfig.KVTimeout) * 0.9),
expectedDeadline: globalCollection.timeoutsConfig.KVTimeout,
},
{
name: "no timeout, with durability level persist to majority",
timeout: 0,
durabilityLevel: DurabilityLevelPersistToMajority,
expectedDurabilityTimeout: time.Duration(float64(globalCollection.timeoutsConfig.KVDurableTimeout) * 0.9),
expectedDeadline: globalCollection.timeoutsConfig.KVDurableTimeout,
},
{
name: "no timeout, with durability level majority and persist master",
timeout: 0,
durabilityLevel: DurabilityLevelMajorityAndPersistOnMaster,
expectedDurabilityTimeout: time.Duration(float64(globalCollection.timeoutsConfig.KVDurableTimeout) * 0.9),
expectedDeadline: globalCollection.timeoutsConfig.KVDurableTimeout,
},
}
for _, tc := range testCases {
suite.T().Run(tc.name, func(tt *testing.T) {
mgr := globalCollection.newKvOpManager("test", nil)
mgr.SetTimeout(tc.timeout)
mgr.SetDuraOptions(0, 0, tc.durabilityLevel)
deadline := mgr.Deadline()
duraTimeout := mgr.DurabilityTimeout()
diff := deadline.Sub(time.Now().Add(tc.expectedDeadline))
if diff > 5*time.Millisecond || diff < -5*time.Millisecond {
tt.Logf("Expected deadline to be %s but was %s, not within 5ms delta",
tc.expectedDeadline.String(), deadline.String())
tt.Fail()
}
if tc.expectedDurabilityTimeout != duraTimeout {
tt.Logf("Expected durable timeout to be %s but was %s",
tc.expectedDurabilityTimeout.String(), duraTimeout.String())
tt.Fail()
}
})
}
}