]> git.saurik.com Git - redis.git/blame - tests/unit/other.tcl
Merge pull request #74 from kmerenkov/issue_620
[redis.git] / tests / unit / other.tcl
CommitLineData
08f55b78 1start_server {tags {"other"}} {
121ffc85 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
98578b57
PN
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
13566085 22 tags {slow} {
30cf7be6 23 if {$::accurate} {set iterations 10000} else {set iterations 1000}
6b6f101c
PN
24 foreach fuzztype {binary alpha compr} {
25 test "FUZZ stresser with data model $fuzztype" {
26 set err 0
30cf7be6 27 for {set i 0} {$i < $iterations} {incr i} {
6b6f101c
PN
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 }
98578b57 35 }
6b6f101c
PN
36 set _ $err
37 } {0}
38 }
98578b57
PN
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
13566085 57 tags {consistency} {
dd3f505f 58 if {![catch {package require sha1}]} {
30cf7be6 59 if {$::accurate} {set numops 10000} else {set numops 1000}
dd3f505f 60 test {Check consistency of different data types after a reload} {
61 r flushdb
30cf7be6 62 createComplexDataset r $numops
dd3f505f 63 set dump [csvdump r]
64 set sha1 [r debug digest]
65 r debug reload
dd3f505f 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"
98578b57 73
dd3f505f 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 }
98578b57
PN
108 }
109
110 test {EXPIRES after a reload (snapshot + append only file)} {
111 r flushdb
112 r set x 10
113 r expire x 1000
13566085 114 r save
115 r debug reload
98578b57
PN
116 set ttl [r ttl x]
117 set e1 [expr {$ttl > 900 && $ttl <= 1000}]
13566085 118 r bgrewriteaof
119 waitForBgrewriteaof r
120 r debug loadaof
98578b57
PN
121 set ttl [r ttl x]
122 set e2 [expr {$ttl > 900 && $ttl <= 1000}]
123 list $e1 $e2
124 } {1 1}
125
13566085 126 tags {protocol} {
322ea972 127 test {PIPELINING stresser (also a regression for the old epoll bug)} {
128 set fd2 [socket $::host $::port]
129 fconfigure $fd2 -encoding binary -translation binary
130 puts -nonewline $fd2 "SELECT 9\r\n"
131 flush $fd2
132 gets $fd2
98578b57 133
322ea972 134 for {set i 0} {$i < 100000} {incr i} {
135 set q {}
136 set val "0000${i}0000"
137 append q "SET key:$i $val\r\n"
138 puts -nonewline $fd2 $q
139 set q {}
140 append q "GET key:$i\r\n"
141 puts -nonewline $fd2 $q
142 }
143 flush $fd2
98578b57 144
322ea972 145 for {set i 0} {$i < 100000} {incr i} {
146 gets $fd2 line
147 gets $fd2 count
148 set count [string range $count 1 end]
149 set val [read $fd2 $count]
150 read $fd2 2
151 }
152 close $fd2
153 set _ 1
154 } {1}
155 }
98578b57
PN
156
157 test {MUTLI / EXEC basics} {
158 r del mylist
159 r rpush mylist a
160 r rpush mylist b
161 r rpush mylist c
162 r multi
163 set v1 [r lrange mylist 0 -1]
164 set v2 [r ping]
165 set v3 [r exec]
166 list $v1 $v2 $v3
167 } {QUEUED QUEUED {{a b c} PONG}}
168
169 test {DISCARD} {
170 r del mylist
171 r rpush mylist a
172 r rpush mylist b
173 r rpush mylist c
174 r multi
175 set v1 [r del mylist]
176 set v2 [r discard]
177 set v3 [r lrange mylist 0 -1]
178 list $v1 $v2 $v3
179 } {QUEUED OK {a b c}}
180
4ea93ad3 181 test {Nested MULTI are not allowed} {
182 set err {}
183 r multi
184 catch {[r multi]} err
185 r exec
186 set _ $err
187 } {*ERR MULTI*}
188
6c682e55
PN
189 test {MULTI where commands alter argc/argv} {
190 r sadd myset a
191 r multi
192 r spop myset
193 list [r exec] [r exists myset]
194 } {a 0}
195
4ea93ad3 196 test {WATCH inside MULTI is not allowed} {
197 set err {}
198 r multi
199 catch {[r watch x]} err
200 r exec
201 set _ $err
202 } {*ERR WATCH*}
203
98578b57
PN
204 test {APPEND basics} {
205 list [r append foo bar] [r get foo] \
206 [r append foo 100] [r get foo]
207 } {3 bar 6 bar100}
208
209 test {APPEND basics, integer encoded values} {
210 set res {}
211 r del foo
212 r append foo 1
213 r append foo 2
214 lappend res [r get foo]
215 r set foo 1
216 r append foo 2
217 lappend res [r get foo]
218 } {12 12}
219
220 test {APPEND fuzzing} {
221 set err {}
222 foreach type {binary alpha compr} {
223 set buf {}
224 r del x
225 for {set i 0} {$i < 1000} {incr i} {
226 set bin [randstring 0 10 $type]
227 append buf $bin
228 r append x $bin
229 }
230 if {$buf != [r get x]} {
231 set err "Expected '$buf' found '[r get x]'"
232 break
233 }
234 }
235 set _ $err
236 } {}
237
98578b57
PN
238 # Leave the user with a clean DB before to exit
239 test {FLUSHDB} {
240 set aux {}
241 r select 9
242 r flushdb
243 lappend aux [r dbsize]
244 r select 10
245 r flushdb
246 lappend aux [r dbsize]
247 } {0 0}
248
249 test {Perform a final SAVE to leave a clean DB on disk} {
0717e3aa 250 waitForBgsave r
98578b57
PN
251 r save
252 } {OK}
253}