summaryrefslogtreecommitdiff
path: root/examples/redis-unstable/tests/unit/introspection-2.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'examples/redis-unstable/tests/unit/introspection-2.tcl')
-rw-r--r--examples/redis-unstable/tests/unit/introspection-2.tcl281
1 files changed, 281 insertions, 0 deletions
diff --git a/examples/redis-unstable/tests/unit/introspection-2.tcl b/examples/redis-unstable/tests/unit/introspection-2.tcl
new file mode 100644
index 0000000..1e98fdb
--- /dev/null
+++ b/examples/redis-unstable/tests/unit/introspection-2.tcl
@@ -0,0 +1,281 @@
1proc cmdstat {cmd} {
2 return [cmdrstat $cmd r]
3}
4
5proc getlru {key} {
6 set objinfo [r debug object $key]
7 foreach info $objinfo {
8 set kvinfo [split $info ":"]
9 if {[string compare [lindex $kvinfo 0] "lru"] == 0} {
10 return [lindex $kvinfo 1]
11 }
12 }
13 fail "Can't get LRU info with DEBUG OBJECT"
14}
15
16start_server {tags {"introspection"}} {
17 test {The microsecond part of the TIME command will not overflow} {
18 set now [r time]
19 set microseconds [lindex $now 1]
20 assert_morethan $microseconds 0
21 assert_lessthan $microseconds 1000000
22 }
23
24 test {TTL, TYPE and EXISTS do not alter the last access time of a key} {
25 r set foo bar
26 after 3000
27 r ttl foo
28 r type foo
29 r exists foo
30 assert {[r object idletime foo] >= 2}
31 }
32
33 test {TOUCH alters the last access time of a key} {
34 r set foo bar
35 after 3000
36 r touch foo
37 assert {[r object idletime foo] < 2}
38 }
39
40 test {Operations in no-touch mode do not alter the last access time of a key} {
41 r set foo bar
42 r client no-touch on
43 set oldlru [getlru foo]
44 after 1100
45 r get foo
46 set newlru [getlru foo]
47 assert_equal $newlru $oldlru
48 r client no-touch off
49 r get foo
50 set newlru [getlru foo]
51 assert_morethan $newlru $oldlru
52 } {} {needs:debug}
53
54 test {Operations in no-touch mode TOUCH alters the last access time of a key} {
55 r set foo bar
56 r client no-touch on
57 set oldlru [getlru foo]
58 after 1100
59 r touch foo
60 set newlru [getlru foo]
61 assert_morethan $newlru $oldlru
62 } {} {needs:debug}
63
64 test {Operations in no-touch mode TOUCH from script alters the last access time of a key} {
65 r set foo bar
66 r client no-touch on
67 set oldlru [getlru foo]
68 after 1100
69 assert_equal {1} [r eval "return redis.call('touch', 'foo')" 0]
70 set newlru [getlru foo]
71 assert_morethan $newlru $oldlru
72 } {} {needs:debug}
73
74 test {TOUCH returns the number of existing keys specified} {
75 r flushdb
76 r set key1{t} 1
77 r set key2{t} 2
78 r touch key0{t} key1{t} key2{t} key3{t}
79 } 2
80
81 test {command stats for GEOADD} {
82 r config resetstat
83 r GEOADD foo 0 0 bar
84 assert_match {*calls=1,*} [cmdstat geoadd]
85 assert_match {} [cmdstat zadd]
86 } {} {needs:config-resetstat}
87
88 test {errors stats for GEOADD} {
89 r config resetstat
90 # make sure geo command will failed
91 r set foo 1
92 assert_error {WRONGTYPE Operation against a key holding the wrong kind of value*} {r GEOADD foo 0 0 bar}
93 assert_match {*calls=1*,rejected_calls=0,failed_calls=1*} [cmdstat geoadd]
94 assert_match {} [cmdstat zadd]
95 } {} {needs:config-resetstat}
96
97 test {command stats for EXPIRE} {
98 r config resetstat
99 r SET foo bar
100 r EXPIRE foo 0
101 assert_match {*calls=1,*} [cmdstat expire]
102 assert_match {} [cmdstat del]
103 } {} {needs:config-resetstat}
104
105 test {command stats for BRPOP} {
106 r config resetstat
107 r LPUSH list foo
108 r BRPOP list 0
109 assert_match {*calls=1,*} [cmdstat brpop]
110 assert_match {} [cmdstat rpop]
111 } {} {needs:config-resetstat}
112
113 test {command stats for MULTI} {
114 r config resetstat
115 r MULTI
116 r set foo{t} bar
117 r GEOADD foo2{t} 0 0 bar
118 r EXPIRE foo2{t} 0
119 r EXEC
120 assert_match {*calls=1,*} [cmdstat multi]
121 assert_match {*calls=1,*} [cmdstat exec]
122 assert_match {*calls=1,*} [cmdstat set]
123 assert_match {*calls=1,*} [cmdstat expire]
124 assert_match {*calls=1,*} [cmdstat geoadd]
125 } {} {needs:config-resetstat}
126
127 test {command stats for scripts} {
128 r config resetstat
129 r set mykey myval
130 r eval {
131 redis.call('set', KEYS[1], 0)
132 redis.call('expire', KEYS[1], 0)
133 redis.call('geoadd', KEYS[1], 0, 0, "bar")
134 } 1 mykey
135 assert_match {*calls=1,*} [cmdstat eval]
136 assert_match {*calls=2,*} [cmdstat set]
137 assert_match {*calls=1,*} [cmdstat expire]
138 assert_match {*calls=1,*} [cmdstat geoadd]
139 } {} {needs:config-resetstat}
140
141 test {COMMAND COUNT get total number of Redis commands} {
142 assert_morethan [r command count] 0
143 }
144
145 test {COMMAND GETKEYS GET} {
146 assert_equal {key} [r command getkeys get key]
147 }
148
149 test {COMMAND GETKEYSANDFLAGS} {
150 assert_equal {{k1 {OW update}}} [r command getkeysandflags set k1 v1]
151 assert_equal {{k1 {OW update}} {k2 {OW update}}} [r command getkeysandflags mset k1 v1 k2 v2]
152 assert_equal {{k1 {RW access delete}} {k2 {RW insert}}} [r command getkeysandflags LMOVE k1 k2 left right]
153 assert_equal {{k1 {RO access}} {k2 {OW update}}} [r command getkeysandflags sort k1 store k2]
154 assert_equal {{k1 {RW update}}} [r command getkeysandflags set k1 v1 IFEQ v1]
155 assert_equal {{k1 {RW access update}}} [r command getkeysandflags set k1 v1 GET]
156 assert_equal {{k1 {RM delete}}} [r command getkeysandflags delex k1]
157 assert_equal {{k1 {RW delete}}} [r command getkeysandflags delex k1 ifeq v1]
158 }
159
160 test {COMMAND GETKEYSANDFLAGS invalid args} {
161 assert_error "ERR Invalid arguments*" {r command getkeysandflags ZINTERSTORE zz 1443677133621497600 asdf}
162 }
163
164 test {COMMAND GETKEYSANDFLAGS MSETEX} {
165 assert_equal {{k1 {OW update}}} [r command getkeysandflags msetex 1 k1 v1 ex 10]
166 assert_equal {{k1 {OW update}} {k2 {OW update}}} [r command getkeysandflags msetex 2 k1 v1 k2 v2 ex 10]
167 assert_equal {{k1 {OW update}} {k2 {OW update}} {k3 {OW update}}} [r command getkeysandflags msetex 3 k1 v1 k2 v2 k3 v3 ex 10]
168 assert_equal {{k1 {OW update}} {k2 {OW update}}} [r command getkeysandflags msetex 2 k1 v1 k2 v2 keepttl]
169 assert_equal {{k1 {OW update}} {k2 {OW update}}} [r command getkeysandflags msetex 2 k1 v1 k2 v2 ex 10 nx]
170 }
171
172 test {COMMAND GETKEYS MEMORY USAGE} {
173 assert_equal {key} [r command getkeys memory usage key]
174 }
175
176 test {COMMAND GETKEYS XGROUP} {
177 assert_equal {key} [r command getkeys xgroup create key groupname $]
178 }
179
180 test {COMMAND GETKEYS EVAL with keys} {
181 assert_equal {key} [r command getkeys eval "return 1" 1 key]
182 }
183
184 test {COMMAND GETKEYS EVAL without keys} {
185 assert_equal {} [r command getkeys eval "return 1" 0]
186 }
187
188 test {COMMAND GETKEYS LCS} {
189 assert_equal {key1 key2} [r command getkeys lcs key1 key2]
190 }
191
192 test {COMMAND GETKEYS MORE THAN 256 KEYS} {
193 set all_keys [list]
194 set numkeys 260
195 for {set i 1} {$i <= $numkeys} {incr i} {
196 lappend all_keys "key$i"
197 }
198 set all_keys_with_target [linsert $all_keys 0 target]
199 # we are using ZUNIONSTORE command since in order to reproduce allocation of a new buffer in getKeysPrepareResult
200 # when numkeys in result > 0
201 # we need a command that the final number of keys is not known in the first call to getKeysPrepareResult
202 # before the fix in that case data of old buffer was not copied to the new result buffer
203 # causing all previous keys (numkeys) data to be uninitialize
204 assert_equal $all_keys_with_target [r command getkeys ZUNIONSTORE target $numkeys {*}$all_keys]
205 }
206
207 test "COMMAND LIST syntax error" {
208 assert_error "ERR syntax error*" {r command list bad_arg}
209 assert_error "ERR syntax error*" {r command list filterby bad_arg}
210 assert_error "ERR syntax error*" {r command list filterby bad_arg bad_arg2}
211 }
212
213 test "COMMAND LIST WITHOUT FILTERBY" {
214 set commands [r command list]
215 assert_not_equal [lsearch $commands "set"] -1
216 assert_not_equal [lsearch $commands "client|list"] -1
217 }
218
219 test "COMMAND LIST FILTERBY ACLCAT against non existing category" {
220 assert_equal {} [r command list filterby aclcat non_existing_category]
221 }
222
223 test "COMMAND LIST FILTERBY ACLCAT - list all commands/subcommands" {
224 set commands [r command list filterby aclcat scripting]
225 assert_not_equal [lsearch $commands "eval"] -1
226 assert_not_equal [lsearch $commands "script|kill"] -1
227
228 # Negative check, a command that should not be here
229 assert_equal [lsearch $commands "set"] -1
230 }
231
232 test "COMMAND LIST FILTERBY PATTERN - list all commands/subcommands" {
233 # Exact command match.
234 assert_equal {set} [r command list filterby pattern set]
235 assert_equal {get} [r command list filterby pattern get]
236
237 # Return the parent command and all the subcommands below it.
238 set commands [r command list filterby pattern config*]
239 assert_not_equal [lsearch $commands "config"] -1
240 assert_not_equal [lsearch $commands "config|get"] -1
241
242 # We can filter subcommands under a parent command.
243 set commands [r command list filterby pattern config|*re*]
244 assert_not_equal [lsearch $commands "config|resetstat"] -1
245 assert_not_equal [lsearch $commands "config|rewrite"] -1
246
247 # We can filter subcommands across parent commands.
248 set commands [r command list filterby pattern cl*help]
249 assert_not_equal [lsearch $commands "client|help"] -1
250 assert_not_equal [lsearch $commands "cluster|help"] -1
251
252 # Negative check, command that doesn't exist.
253 assert_equal {} [r command list filterby pattern non_exists]
254 assert_equal {} [r command list filterby pattern non_exists*]
255 }
256
257 test "COMMAND LIST FILTERBY MODULE against non existing module" {
258 # This should be empty, the real one is in subcommands.tcl
259 assert_equal {} [r command list filterby module non_existing_module]
260 }
261
262 test {COMMAND INFO of invalid subcommands} {
263 assert_equal {{}} [r command info get|key]
264 assert_equal {{}} [r command info config|get|key]
265 }
266
267 foreach cmd {SET GET MSET BITFIELD LMOVE LPOP BLPOP PING MEMORY MEMORY|USAGE RENAME GEORADIUS_RO} {
268 test "$cmd command will not be marked with movablekeys" {
269 set info [lindex [r command info $cmd] 0]
270 assert_no_match {*movablekeys*} [lindex $info 2]
271 }
272 }
273
274 foreach cmd {ZUNIONSTORE XREAD EVAL SORT SORT_RO MIGRATE GEORADIUS} {
275 test "$cmd command is marked with movablekeys" {
276 set info [lindex [r command info $cmd] 0]
277 assert_match {*movablekeys*} [lindex $info 2]
278 }
279 }
280
281}