]> git.saurik.com Git - redis.git/blob - tests/unit/other.tcl
d2663572f6dab3df0605cdd6a532eac46eaa35d4
[redis.git] / tests / unit / other.tcl
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} {
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} {
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 r save
106 r debug reload
107 set ttl [r ttl x]
108 set e1 [expr {$ttl > 900 && $ttl <= 1000}]
109 r bgrewriteaof
110 waitForBgrewriteaof r
111 r debug loadaof
112 set ttl [r ttl x]
113 set e2 [expr {$ttl > 900 && $ttl <= 1000}]
114 list $e1 $e2
115 } {1 1}
116
117 tags {protocol} {
118 test {PIPELINING stresser (also a regression for the old epoll bug)} {
119 set fd2 [socket $::host $::port]
120 fconfigure $fd2 -encoding binary -translation binary
121 puts -nonewline $fd2 "SELECT 9\r\n"
122 flush $fd2
123 gets $fd2
124
125 for {set i 0} {$i < 100000} {incr i} {
126 set q {}
127 set val "0000${i}0000"
128 append q "SET key:$i $val\r\n"
129 puts -nonewline $fd2 $q
130 set q {}
131 append q "GET key:$i\r\n"
132 puts -nonewline $fd2 $q
133 }
134 flush $fd2
135
136 for {set i 0} {$i < 100000} {incr i} {
137 gets $fd2 line
138 gets $fd2 count
139 set count [string range $count 1 end]
140 set val [read $fd2 $count]
141 read $fd2 2
142 }
143 close $fd2
144 set _ 1
145 } {1}
146 }
147
148 test {MUTLI / EXEC basics} {
149 r del mylist
150 r rpush mylist a
151 r rpush mylist b
152 r rpush mylist c
153 r multi
154 set v1 [r lrange mylist 0 -1]
155 set v2 [r ping]
156 set v3 [r exec]
157 list $v1 $v2 $v3
158 } {QUEUED QUEUED {{a b c} PONG}}
159
160 test {DISCARD} {
161 r del mylist
162 r rpush mylist a
163 r rpush mylist b
164 r rpush mylist c
165 r multi
166 set v1 [r del mylist]
167 set v2 [r discard]
168 set v3 [r lrange mylist 0 -1]
169 list $v1 $v2 $v3
170 } {QUEUED OK {a b c}}
171
172 test {Nested MULTI are not allowed} {
173 set err {}
174 r multi
175 catch {[r multi]} err
176 r exec
177 set _ $err
178 } {*ERR MULTI*}
179
180 test {MULTI where commands alter argc/argv} {
181 r sadd myset a
182 r multi
183 r spop myset
184 list [r exec] [r exists myset]
185 } {a 0}
186
187 test {WATCH inside MULTI is not allowed} {
188 set err {}
189 r multi
190 catch {[r watch x]} err
191 r exec
192 set _ $err
193 } {*ERR WATCH*}
194
195 test {APPEND basics} {
196 list [r append foo bar] [r get foo] \
197 [r append foo 100] [r get foo]
198 } {3 bar 6 bar100}
199
200 test {APPEND basics, integer encoded values} {
201 set res {}
202 r del foo
203 r append foo 1
204 r append foo 2
205 lappend res [r get foo]
206 r set foo 1
207 r append foo 2
208 lappend res [r get foo]
209 } {12 12}
210
211 test {APPEND fuzzing} {
212 set err {}
213 foreach type {binary alpha compr} {
214 set buf {}
215 r del x
216 for {set i 0} {$i < 1000} {incr i} {
217 set bin [randstring 0 10 $type]
218 append buf $bin
219 r append x $bin
220 }
221 if {$buf != [r get x]} {
222 set err "Expected '$buf' found '[r get x]'"
223 break
224 }
225 }
226 set _ $err
227 } {}
228
229 # Leave the user with a clean DB before to exit
230 test {FLUSHDB} {
231 set aux {}
232 r select 9
233 r flushdb
234 lappend aux [r dbsize]
235 r select 10
236 r flushdb
237 lappend aux [r dbsize]
238 } {0 0}
239
240 test {Perform a final SAVE to leave a clean DB on disk} {
241 r save
242 } {OK}
243 }