]>
Commit | Line | Data |
---|---|---|
1 | start_server {tags {"other"}} { | |
2 | if {$::force_failure} { | |
3 | # This is used just for test suite development purposes. | |
4 | test {Failing test} { | |
5 | format err | |
6 | } {ok} | |
7 | } | |
8 | ||
9 | test {SAVE - make sure there are all the types as values} { | |
10 | # Wait for a background saving in progress to terminate | |
11 | waitForBgsave r | |
12 | r lpush mysavelist hello | |
13 | r lpush mysavelist world | |
14 | r set myemptykey {} | |
15 | r set mynormalkey {blablablba} | |
16 | r zadd mytestzset 10 a | |
17 | r zadd mytestzset 20 b | |
18 | r zadd mytestzset 30 c | |
19 | r save | |
20 | } {OK} | |
21 | ||
22 | tags {slow} { | |
23 | if {$::accurate} {set iterations 10000} else {set iterations 1000} | |
24 | foreach fuzztype {binary alpha compr} { | |
25 | test "FUZZ stresser with data model $fuzztype" { | |
26 | set err 0 | |
27 | for {set i 0} {$i < $iterations} {incr i} { | |
28 | set fuzz [randstring 0 512 $fuzztype] | |
29 | r set foo $fuzz | |
30 | set got [r get foo] | |
31 | if {$got ne $fuzz} { | |
32 | set err [list $fuzz $got] | |
33 | break | |
34 | } | |
35 | } | |
36 | set _ $err | |
37 | } {0} | |
38 | } | |
39 | } | |
40 | ||
41 | test {BGSAVE} { | |
42 | waitForBgsave r | |
43 | r flushdb | |
44 | r save | |
45 | r set x 10 | |
46 | r bgsave | |
47 | waitForBgsave r | |
48 | r debug reload | |
49 | r get x | |
50 | } {10} | |
51 | ||
52 | test {SELECT an out of range DB} { | |
53 | catch {r select 1000000} err | |
54 | set _ $err | |
55 | } {*invalid*} | |
56 | ||
57 | tags {consistency} { | |
58 | if {![catch {package require sha1}]} { | |
59 | if {$::accurate} {set numops 10000} else {set numops 1000} | |
60 | test {Check consistency of different data types after a reload} { | |
61 | r flushdb | |
62 | createComplexDataset r $numops | |
63 | set dump [csvdump r] | |
64 | set sha1 [r debug digest] | |
65 | r debug reload | |
66 | set sha1_after [r debug digest] | |
67 | if {$sha1 eq $sha1_after} { | |
68 | set _ 1 | |
69 | } else { | |
70 | set newdump [csvdump r] | |
71 | puts "Consistency test failed!" | |
72 | puts "You can inspect the two dumps in /tmp/repldump*.txt" | |
73 | ||
74 | set fd [open /tmp/repldump1.txt w] | |
75 | puts $fd $dump | |
76 | close $fd | |
77 | set fd [open /tmp/repldump2.txt w] | |
78 | puts $fd $newdump | |
79 | close $fd | |
80 | ||
81 | set _ 0 | |
82 | } | |
83 | } {1} | |
84 | ||
85 | test {Same dataset digest if saving/reloading as AOF?} { | |
86 | r bgrewriteaof | |
87 | waitForBgrewriteaof r | |
88 | r debug loadaof | |
89 | set sha1_after [r debug digest] | |
90 | if {$sha1 eq $sha1_after} { | |
91 | set _ 1 | |
92 | } else { | |
93 | set newdump [csvdump r] | |
94 | puts "Consistency test failed!" | |
95 | puts "You can inspect the two dumps in /tmp/aofdump*.txt" | |
96 | ||
97 | set fd [open /tmp/aofdump1.txt w] | |
98 | puts $fd $dump | |
99 | close $fd | |
100 | set fd [open /tmp/aofdump2.txt w] | |
101 | puts $fd $newdump | |
102 | close $fd | |
103 | ||
104 | set _ 0 | |
105 | } | |
106 | } {1} | |
107 | } | |
108 | } | |
109 | ||
110 | test {EXPIRES after a reload (snapshot + append only file rewrite)} { | |
111 | r flushdb | |
112 | r set x 10 | |
113 | r expire x 1000 | |
114 | r save | |
115 | r debug reload | |
116 | set ttl [r ttl x] | |
117 | set e1 [expr {$ttl > 900 && $ttl <= 1000}] | |
118 | r bgrewriteaof | |
119 | waitForBgrewriteaof r | |
120 | r debug loadaof | |
121 | set ttl [r ttl x] | |
122 | set e2 [expr {$ttl > 900 && $ttl <= 1000}] | |
123 | list $e1 $e2 | |
124 | } {1 1} | |
125 | ||
126 | test {EXPIRES after AOF reload (without rewrite)} { | |
127 | r flushdb | |
128 | r config set appendonly yes | |
129 | r set x somevalue | |
130 | r expire x 1000 | |
131 | r setex y 2000 somevalue | |
132 | r set z somevalue | |
133 | r expireat z [expr {[clock seconds]+3000}] | |
134 | ||
135 | # Milliseconds variants | |
136 | r set px somevalue | |
137 | r pexpire px 1000000 | |
138 | r psetex py 2000000 somevalue | |
139 | r set pz somevalue | |
140 | r pexpireat pz [expr {([clock seconds]+3000)*1000}] | |
141 | ||
142 | # Reload and check | |
143 | r debug loadaof | |
144 | set ttl [r ttl x] | |
145 | assert {$ttl > 900 && $ttl <= 1000} | |
146 | set ttl [r ttl y] | |
147 | assert {$ttl > 1900 && $ttl <= 2000} | |
148 | set ttl [r ttl z] | |
149 | assert {$ttl > 2900 && $ttl <= 3000} | |
150 | set ttl [r ttl px] | |
151 | assert {$ttl > 900 && $ttl <= 1000} | |
152 | set ttl [r ttl py] | |
153 | assert {$ttl > 1900 && $ttl <= 2000} | |
154 | set ttl [r ttl pz] | |
155 | assert {$ttl > 2900 && $ttl <= 3000} | |
156 | r config set appendonly no | |
157 | } | |
158 | ||
159 | tags {protocol} { | |
160 | test {PIPELINING stresser (also a regression for the old epoll bug)} { | |
161 | set fd2 [socket $::host $::port] | |
162 | fconfigure $fd2 -encoding binary -translation binary | |
163 | puts -nonewline $fd2 "SELECT 9\r\n" | |
164 | flush $fd2 | |
165 | gets $fd2 | |
166 | ||
167 | for {set i 0} {$i < 100000} {incr i} { | |
168 | set q {} | |
169 | set val "0000${i}0000" | |
170 | append q "SET key:$i $val\r\n" | |
171 | puts -nonewline $fd2 $q | |
172 | set q {} | |
173 | append q "GET key:$i\r\n" | |
174 | puts -nonewline $fd2 $q | |
175 | } | |
176 | flush $fd2 | |
177 | ||
178 | for {set i 0} {$i < 100000} {incr i} { | |
179 | gets $fd2 line | |
180 | gets $fd2 count | |
181 | set count [string range $count 1 end] | |
182 | set val [read $fd2 $count] | |
183 | read $fd2 2 | |
184 | } | |
185 | close $fd2 | |
186 | set _ 1 | |
187 | } {1} | |
188 | } | |
189 | ||
190 | test {MUTLI / EXEC basics} { | |
191 | r del mylist | |
192 | r rpush mylist a | |
193 | r rpush mylist b | |
194 | r rpush mylist c | |
195 | r multi | |
196 | set v1 [r lrange mylist 0 -1] | |
197 | set v2 [r ping] | |
198 | set v3 [r exec] | |
199 | list $v1 $v2 $v3 | |
200 | } {QUEUED QUEUED {{a b c} PONG}} | |
201 | ||
202 | test {DISCARD} { | |
203 | r del mylist | |
204 | r rpush mylist a | |
205 | r rpush mylist b | |
206 | r rpush mylist c | |
207 | r multi | |
208 | set v1 [r del mylist] | |
209 | set v2 [r discard] | |
210 | set v3 [r lrange mylist 0 -1] | |
211 | list $v1 $v2 $v3 | |
212 | } {QUEUED OK {a b c}} | |
213 | ||
214 | test {Nested MULTI are not allowed} { | |
215 | set err {} | |
216 | r multi | |
217 | catch {[r multi]} err | |
218 | r exec | |
219 | set _ $err | |
220 | } {*ERR MULTI*} | |
221 | ||
222 | test {MULTI where commands alter argc/argv} { | |
223 | r sadd myset a | |
224 | r multi | |
225 | r spop myset | |
226 | list [r exec] [r exists myset] | |
227 | } {a 0} | |
228 | ||
229 | test {WATCH inside MULTI is not allowed} { | |
230 | set err {} | |
231 | r multi | |
232 | catch {[r watch x]} err | |
233 | r exec | |
234 | set _ $err | |
235 | } {*ERR WATCH*} | |
236 | ||
237 | test {APPEND basics} { | |
238 | list [r append foo bar] [r get foo] \ | |
239 | [r append foo 100] [r get foo] | |
240 | } {3 bar 6 bar100} | |
241 | ||
242 | test {APPEND basics, integer encoded values} { | |
243 | set res {} | |
244 | r del foo | |
245 | r append foo 1 | |
246 | r append foo 2 | |
247 | lappend res [r get foo] | |
248 | r set foo 1 | |
249 | r append foo 2 | |
250 | lappend res [r get foo] | |
251 | } {12 12} | |
252 | ||
253 | test {APPEND fuzzing} { | |
254 | set err {} | |
255 | foreach type {binary alpha compr} { | |
256 | set buf {} | |
257 | r del x | |
258 | for {set i 0} {$i < 1000} {incr i} { | |
259 | set bin [randstring 0 10 $type] | |
260 | append buf $bin | |
261 | r append x $bin | |
262 | } | |
263 | if {$buf != [r get x]} { | |
264 | set err "Expected '$buf' found '[r get x]'" | |
265 | break | |
266 | } | |
267 | } | |
268 | set _ $err | |
269 | } {} | |
270 | ||
271 | # Leave the user with a clean DB before to exit | |
272 | test {FLUSHDB} { | |
273 | set aux {} | |
274 | r select 9 | |
275 | r flushdb | |
276 | lappend aux [r dbsize] | |
277 | r select 10 | |
278 | r flushdb | |
279 | lappend aux [r dbsize] | |
280 | } {0 0} | |
281 | ||
282 | test {Perform a final SAVE to leave a clean DB on disk} { | |
283 | waitForBgsave r | |
284 | r save | |
285 | } {OK} | |
286 | } |