Debian Codegraph @

tests/unittests/command_parse/test_server.py

raw
1 def test_client_setname(judge_command):
2 judge_command(
3 "CLIENT SETNAME foobar", {"command": "CLIENT SETNAME", "value": "foobar"}
4 )
5
6
7 def test_client_unblock(judge_command):
8 judge_command(
9 "CLIENT UNBLOCK 33 TIMEOUT",
10 {"command": "CLIENT UNBLOCK", "clientid": "33", "error": "TIMEOUT"},
11 )
12 judge_command("CLIENT UNBLOCK 33", {"command": "CLIENT UNBLOCK", "clientid": "33"})
13
14
15 def test_flushdb(judge_command):
16 judge_command("FLUSHDB async", {"command": "FLUSHDB", "async": "async"})
17 judge_command("FLUSHDB", {"command": "FLUSHDB"})
18 judge_command("FLUSHDB ASYNC", {"command": "FLUSHDB", "async": "ASYNC"})
19 judge_command("FLUSHALL ASYNC", {"command": "FLUSHALL", "async": "ASYNC"})
20
21
22 def test_client_list(judge_command):
23 judge_command("client list", {"command": "client list"})
24 judge_command("client list TYPE REPLICA1", None)
25 judge_command(
26 "client list type master",
27 {"command": "client list", "type_const": "type", "conntype": "master"},
28 )
29 judge_command(
30 "client list TYPE REPLICA",
31 {"command": "client list", "type_const": "TYPE", "conntype": "REPLICA"},
32 )
33
34 judge_command(
35 "client list TYPE REPLICA id 1 2 3",
36 {
37 "command": "client list",
38 "type_const": "TYPE",
39 "conntype": "REPLICA",
40 "clientids": "1 2 3",
41 },
42 )
43 judge_command(
44 "client list ID 1 2 3",
45 {"command": "client list", "clientids": "1 2 3"},
46 )
47
48
49 def test_configset(judge_command):
50 """CONFIG SET accepts one or more parameter-value pairs (per commands.json since 7.0)."""
51 judge_command(
52 "config set foo bar",
53 {"command": "config set", "parameter": "foo", "value": "bar"},
54 )
55 judge_command(
56 "config set requirepass ''",
57 {"command": "config set", "parameter": "requirepass", "value": "''"},
58 )
59 # Multiple parameter-value pairs (Redis 7.0+); grammar accepts all, parser captures last
60 judge_command(
61 "config set maxmemory 256mb timeout 3000",
62 {"command": "config set", "parameter": "timeout", "value": "3000"},
63 )
64
65
66 def test_command_info(judge_command):
67 """COMMAND INFO accepts 0 or more command names (per commands.json, 7.0+ allows no arg)."""
68 judge_command("COMMAND INFO", {"command": "COMMAND INFO"})
69
70
71 def test_command_list(judge_command):
72 """COMMAND LIST (since 7.0) accepts optional FILTERBY (per commands.json)."""
73 judge_command("COMMAND LIST", {"command": "COMMAND LIST"})
74 judge_command(
75 "COMMAND LIST FILTERBY MODULE mymod",
76 {"command": "COMMAND LIST", "parameters": "FILTERBY MODULE mymod"},
77 )
78
79
80 def test_command_docs(judge_command):
81 """COMMAND DOCS (since 7.0) accepts 0 or more command names (per commands.json)."""
82 judge_command("COMMAND DOCS", {"command": "COMMAND DOCS"})
83 judge_command(
84 "COMMAND DOCS GET SET",
85 {"command": "COMMAND DOCS", "parameters": "GET SET"},
86 )
87
88
89 def test_memory_usage(judge_command):
90 """MEMORY USAGE key [SAMPLES count] (per commands.json)."""
91 judge_command("MEMORY USAGE mykey", {"command": "MEMORY USAGE", "key": "mykey"})
92 judge_command(
93 "MEMORY USAGE mykey SAMPLES 5",
94 {
95 "command": "MEMORY USAGE",
96 "key": "mykey",
97 "samples": "SAMPLES",
98 "count": "5",
99 },
100 )
101 judge_command(
102 "COMMAND INFO get set",
103 {"command": "COMMAND INFO", "parameters": "get set"},
104 )
105 judge_command(
106 "command info GET",
107 {"command": "command info", "parameters": "GET"},
108 )
109
110
111 def test_acl_dryrun(judge_command):
112 """ACL DRYRUN username command [arg ...] (per commands.json)."""
113 judge_command(
114 "ACL DRYRUN alice SET foo bar",
115 {
116 "command": "ACL DRYRUN",
117 "username": "alice",
118 "parameter": "SET",
119 "parameters": "foo bar",
120 },
121 )
122 judge_command(
123 "ACL DRYRUN bob GET mykey",
124 {
125 "command": "ACL DRYRUN",
126 "username": "bob",
127 "parameter": "GET",
128 "parameters": "mykey",
129 },
130 )
131 judge_command(
132 "ACL DRYRUN alice SET",
133 {"command": "ACL DRYRUN", "username": "alice", "parameter": "SET"},
134 )
135
136
137 def test_config_get(judge_command):
138 """CONFIG GET accepts one or more parameters (per commands.json), not parameter+value."""
139 judge_command(
140 "CONFIG GET maxmemory",
141 {"command": "CONFIG GET", "parameters": "maxmemory"},
142 )
143 judge_command(
144 "CONFIG GET maxmemory timeout",
145 {"command": "CONFIG GET", "parameters": "maxmemory timeout"},
146 )
147 judge_command(
148 "config get *max-*-entries*",
149 {"command": "config get", "parameters": "*max-*-entries*"},
150 )
151 judge_command("CONFIG GET", None)
152
153
154 def test_shutdown(judge_command):
155 judge_command("shutdown save", {"command": "shutdown", "shutdown": "save"})
156 judge_command("shutdown NOSAVE", {"command": "shutdown", "shutdown": "NOSAVE"})
157
158
159 def test_clientpause(judge_command):
160 judge_command("client pause 3000", {"command": "client pause", "timeout": "3000"})
161
162
163 def test_client_reply(judge_command):
164 judge_command("client reply on", {"command": "client reply", "switch": "on"})
165
166
167 def test_client_kill(judge_command):
168 judge_command(
169 "CLIENT KILL addr 127.0.0.1:12345 type pubsub",
170 {
171 "command": "CLIENT KILL",
172 "addr": "addr",
173 "ip_port": "127.0.0.1:12345",
174 "type_const": "type",
175 "conntype": "pubsub",
176 },
177 )
178 judge_command(
179 "CLIENT KILL 127.0.0.1:12345 ",
180 {"command": "CLIENT KILL", "ip_port": "127.0.0.1:12345"},
181 )
182 judge_command(
183 "CLIENT KILL ADDR 127.0.0.1:12345 ",
184 {"command": "CLIENT KILL", "ip_port": "127.0.0.1:12345", "addr": "ADDR"},
185 )
186 judge_command(
187 "CLIENT KILL LADDR 127.0.0.1:12345 ",
188 {"command": "CLIENT KILL", "ip_port": "127.0.0.1:12345", "laddr": "LADDR"},
189 )
190 judge_command(
191 "CLIENT KILL USER myuser",
192 {"command": "CLIENT KILL", "const_user": "USER", "username": "myuser"},
193 )
194 judge_command(
195 "CLIENT KILL id 123455 type pubsub skipme no",
196 {
197 "command": "CLIENT KILL",
198 "const_id": "id",
199 "clientid": "123455",
200 "type_const": "type",
201 "conntype": "pubsub",
202 "skipme": "skipme",
203 "yes": "no",
204 },
205 )
206
207
208 def test_client_kill_username(judge_command):
209 """since redis-server 6.0"""
210 judge_command(
211 "client kill USER default",
212 {"command": "client kill", "const_user": "USER", "username": "default"},
213 )
214
215
216 def test_client_kill_unordered_arguments(judge_command):
217 judge_command(
218 "CLIENT KILL type pubsub addr 127.0.0.1:12345",
219 {
220 "command": "CLIENT KILL",
221 "addr": "addr",
222 "ip_port": "127.0.0.1:12345",
223 "type_const": "type",
224 "conntype": "pubsub",
225 },
226 )
227
228
229 def test_psync(judge_command):
230 judge_command(
231 "PSYNC abc 123", {"command": "PSYNC", "replicationid": "abc", "offset": "123"}
232 )
233 judge_command("PSYNC", None)
234
235
236 def test_latency_graph(judge_command):
237 judge_command(
238 "latency graph command", {"command": "latency graph", "graphevent": "command"}
239 )
240 judge_command(
241 "latency graph fork", {"command": "latency graph", "graphevent": "fork"}
242 )
243 judge_command("latency graph", None)
244
245
246 def test_latency_reset(judge_command):
247 judge_command(
248 "latency reset command fork aof-fsync-always",
249 {"command": "latency reset", "graphevent": "aof-fsync-always"},
250 )
251 judge_command(
252 "latency reset fork", {"command": "latency reset", "graphevent": "fork"}
253 )
254 judge_command("latency reset", {"command": "latency reset"})
255
256
257 def test_lolwut(judge_command):
258 judge_command("lolwut", {"command": "lolwut"})
259 # only works before redis 6
260 judge_command("lolwut 5", {"command": "lolwut", "any": "5"})
261 judge_command("lolwut 5 1", {"command": "lolwut", "any": "5 1"})
262 # redis 6
263 judge_command(
264 "lolwut VERSION 5 5",
265 {"command": "lolwut", "version": "VERSION", "version_num": "5", "any": "5"},
266 )
267
268
269 def test_info(judge_command):
270 judge_command("info cpu", {"command": "info", "section": "cpu"})
271 judge_command("info", {"command": "info"})
272 judge_command("info all", {"command": "info", "section": "all"})
273 judge_command("info CPU", {"command": "info", "section": "CPU"})
274
275
276 def test_bgsave(judge_command):
277 judge_command("bgsave", {"command": "bgsave"})
278 judge_command("bgsave schedule", {"command": "bgsave", "schedule": "schedule"})
279 judge_command("BGSAVE SCHEDULE", {"command": "BGSAVE", "schedule": "SCHEDULE"})
280
281
282 def test_acl_cat(judge_command):
283 judge_command("acl cat", {"command": "acl cat"})
284 judge_command("acl CAT", {"command": "acl CAT"})
285 judge_command(
286 "ACL CAT scripting", {"command": "ACL CAT", "categoryname": "scripting"}
287 )
288 judge_command("ACL CAT WATCH", {"command": "ACL CAT", "categoryname": "WATCH"})
289
290
291 def test_acl_deluser(judge_command):
292 judge_command(
293 "acl deluser laixintao", {"command": "acl deluser", "username": "laixintao"}
294 )
295 judge_command(
296 "acl deluser laixintao antirez",
297 {"command": "acl deluser", "username": "antirez"},
298 )
299
300
301 def test_acl_log(judge_command):
302 judge_command("acl log 2", {"command": "acl log", "count": "2"})
303 judge_command("acl log reset", {"command": "acl log", "reset_const": "reset"})
304 judge_command("acl log ", {"command": "acl log"})
305
306
307 def test_acl_setuser(judge_command):
308 judge_command("ACL SETUSER alice", {"command": "ACL SETUSER", "username": "alice"})
309 judge_command(
310 "ACL SETUSER alice on >p1pp0 ~cached:* +get",
311 {"command": "ACL SETUSER", "username": "alice", "rule": "+get"},
312 )
313 judge_command(
314 "ACL SETUSER alan allkeys +@string +@set -SADD >alanpassword",
315 {"command": "ACL SETUSER", "username": "alan", "rule": ">alanpassword"},
316 )
317
318
319 def test_acl_getuser(judge_command):
320 judge_command("acl getuser alan", {"command": "acl getuser", "username": "alan"})
321 judge_command("acl getuser", None)
322
323
324 def test_failover(judge_command):
325 judge_command(
326 "failover to 10.0.0.5 7379 abort timeout 101",
327 {
328 "command": "failover",
329 "to_const": "to",
330 "host": "10.0.0.5",
331 "port": "7379",
332 "abort_const": "abort",
333 "timeout_const": "timeout",
334 "millisecond": "101",
335 },
336 )
337 judge_command(
338 "failover abort timeout 101",
339 {
340 "command": "failover",
341 "abort_const": "abort",
342 "timeout_const": "timeout",
343 "millisecond": "101",
344 },
345 )
346 judge_command(
347 "failover timeout 101",
348 {
349 "command": "failover",
350 "timeout_const": "timeout",
351 "millisecond": "101",
352 },
353 )
354 judge_command(
355 "failover to 10.0.0.5 7379 force abort timeout 101",
356 {
357 "command": "failover",
358 "to_const": "to",
359 "force": "force",
360 "host": "10.0.0.5",
361 "port": "7379",
362 "abort_const": "abort",
363 "timeout_const": "timeout",
364 "millisecond": "101",
365 },
366 )