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