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