]> git.saurik.com Git - redis.git/blob - tests/unit/other.tcl
Merge remote-tracking branch 'origin/unstable' into unstable
[redis.git] / tests / unit / other.tcl
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 waitForBgrewriteaof r
144 r debug loadaof
145 set ttl [r ttl x]
146 assert {$ttl > 900 && $ttl <= 1000}
147 set ttl [r ttl y]
148 assert {$ttl > 1900 && $ttl <= 2000}
149 set ttl [r ttl z]
150 assert {$ttl > 2900 && $ttl <= 3000}
151 set ttl [r ttl px]
152 assert {$ttl > 900 && $ttl <= 1000}
153 set ttl [r ttl py]
154 assert {$ttl > 1900 && $ttl <= 2000}
155 set ttl [r ttl pz]
156 assert {$ttl > 2900 && $ttl <= 3000}
157 r config set appendonly no
158 }
159
160 tags {protocol} {
161 test {PIPELINING stresser (also a regression for the old epoll bug)} {
162 set fd2 [socket $::host $::port]
163 fconfigure $fd2 -encoding binary -translation binary
164 puts -nonewline $fd2 "SELECT 9\r\n"
165 flush $fd2
166 gets $fd2
167
168 for {set i 0} {$i < 100000} {incr i} {
169 set q {}
170 set val "0000${i}0000"
171 append q "SET key:$i $val\r\n"
172 puts -nonewline $fd2 $q
173 set q {}
174 append q "GET key:$i\r\n"
175 puts -nonewline $fd2 $q
176 }
177 flush $fd2
178
179 for {set i 0} {$i < 100000} {incr i} {
180 gets $fd2 line
181 gets $fd2 count
182 set count [string range $count 1 end]
183 set val [read $fd2 $count]
184 read $fd2 2
185 }
186 close $fd2
187 set _ 1
188 } {1}
189 }
190
191 test {MUTLI / EXEC basics} {
192 r del mylist
193 r rpush mylist a
194 r rpush mylist b
195 r rpush mylist c
196 r multi
197 set v1 [r lrange mylist 0 -1]
198 set v2 [r ping]
199 set v3 [r exec]
200 list $v1 $v2 $v3
201 } {QUEUED QUEUED {{a b c} PONG}}
202
203 test {DISCARD} {
204 r del mylist
205 r rpush mylist a
206 r rpush mylist b
207 r rpush mylist c
208 r multi
209 set v1 [r del mylist]
210 set v2 [r discard]
211 set v3 [r lrange mylist 0 -1]
212 list $v1 $v2 $v3
213 } {QUEUED OK {a b c}}
214
215 test {Nested MULTI are not allowed} {
216 set err {}
217 r multi
218 catch {[r multi]} err
219 r exec
220 set _ $err
221 } {*ERR MULTI*}
222
223 test {MULTI where commands alter argc/argv} {
224 r sadd myset a
225 r multi
226 r spop myset
227 list [r exec] [r exists myset]
228 } {a 0}
229
230 test {WATCH inside MULTI is not allowed} {
231 set err {}
232 r multi
233 catch {[r watch x]} err
234 r exec
235 set _ $err
236 } {*ERR WATCH*}
237
238 test {APPEND basics} {
239 list [r append foo bar] [r get foo] \
240 [r append foo 100] [r get foo]
241 } {3 bar 6 bar100}
242
243 test {APPEND basics, integer encoded values} {
244 set res {}
245 r del foo
246 r append foo 1
247 r append foo 2
248 lappend res [r get foo]
249 r set foo 1
250 r append foo 2
251 lappend res [r get foo]
252 } {12 12}
253
254 test {APPEND fuzzing} {
255 set err {}
256 foreach type {binary alpha compr} {
257 set buf {}
258 r del x
259 for {set i 0} {$i < 1000} {incr i} {
260 set bin [randstring 0 10 $type]
261 append buf $bin
262 r append x $bin
263 }
264 if {$buf != [r get x]} {
265 set err "Expected '$buf' found '[r get x]'"
266 break
267 }
268 }
269 set _ $err
270 } {}
271
272 # Leave the user with a clean DB before to exit
273 test {FLUSHDB} {
274 set aux {}
275 r select 9
276 r flushdb
277 lappend aux [r dbsize]
278 r select 10
279 r flushdb
280 lappend aux [r dbsize]
281 } {0 0}
282
283 test {Perform a final SAVE to leave a clean DB on disk} {
284 waitForBgsave r
285 r save
286 } {OK}
287 }