]> git.saurik.com Git - redis.git/blame - tests/unit/protocol.tcl
Test SDIFF with first set empty.
[redis.git] / tests / unit / protocol.tcl
CommitLineData
08f55b78 1start_server {tags {"protocol"}} {
dc11daf3
PN
2 test "Handle an empty query" {
3 reconnect
4 r write "\r\n"
5 r flush
6 assert_equal "PONG" [r ping]
7 }
98578b57 8
dc11daf3
PN
9 test "Negative multibulk length" {
10 reconnect
11 r write "*-10\r\n"
12 r flush
13 assert_equal PONG [r ping]
14 }
98578b57 15
b19c33d4
PN
16 test "Out of range multibulk length" {
17 reconnect
18 r write "*20000000\r\n"
19 r flush
20 assert_error "*invalid multibulk length*" {r read}
21 }
22
dc11daf3
PN
23 test "Wrong multibulk payload header" {
24 reconnect
25 r write "*3\r\n\$3\r\nSET\r\n\$1\r\nx\r\nfooz\r\n"
26 r flush
27 assert_error "*expected '$', got 'f'*" {r read}
28 }
98578b57 29
dc11daf3
PN
30 test "Negative multibulk payload length" {
31 reconnect
32 r write "*3\r\n\$3\r\nSET\r\n\$1\r\nx\r\n\$-10\r\n"
33 r flush
34 assert_error "*invalid bulk length*" {r read}
35 }
98578b57 36
dc11daf3
PN
37 test "Out of range multibulk payload length" {
38 reconnect
39 r write "*3\r\n\$3\r\nSET\r\n\$1\r\nx\r\n\$2000000000\r\n"
40 r flush
41 assert_error "*invalid bulk length*" {r read}
42 }
01daeece 43
dc11daf3
PN
44 test "Non-number multibulk payload length" {
45 reconnect
46 r write "*3\r\n\$3\r\nSET\r\n\$1\r\nx\r\n\$blabla\r\n"
47 r flush
48 assert_error "*invalid bulk length*" {r read}
49 }
98578b57 50
dc11daf3
PN
51 test "Multi bulk request not followed by bulk arguments" {
52 reconnect
53 r write "*1\r\nfoo\r\n"
54 r flush
55 assert_error "*expected '$', got 'f'*" {r read}
56 }
57
58 test "Generic wrong number of args" {
59 reconnect
60 assert_error "*wrong*arguments*ping*" {r ping x y z}
61 }
06f8a473 62
63 set c 0
64 foreach seq [list "\x00" "*\x00" "$\x00"] {
65 incr c
66 test "Protocol desync regression test #$c" {
67 set s [socket [srv 0 host] [srv 0 port]]
68 puts -nonewline $s $seq
69 set payload [string repeat A 1024]"\n"
70 set test_start [clock seconds]
71 set test_time_limit 5
72 while 1 {
73 if {[catch {
74 puts -nonewline $s payload
75 flush $s
76 incr payload_size [string length $payload]
77 }]} {
78 set retval [gets $s]
79 close $s
80 break
81 } else {
82 set elapsed [expr {[clock seconds]-$test_start}]
83 if {$elapsed > $test_time_limit} {
84 close $s
85 error "assertion:Redis did not closed connection after protocol desync"
86 }
87 }
88 }
89 set retval
90 } {*Protocol error*}
91 }
92 unset c
98578b57 93}
4bb1ccc6 94
95start_server {tags {"regression"}} {
96 test "Regression for a crash with blocking ops and pipelining" {
97 set rd [redis_deferring_client]
98 set fd [r channel]
99 set proto "*3\r\n\$5\r\nBLPOP\r\n\$6\r\nnolist\r\n\$1\r\n0\r\n"
100 puts -nonewline $fd $proto$proto
101 flush $fd
102 set res {}
103
104 $rd rpush nolist a
105 $rd read
106 $rd rpush nolist a
107 $rd read
108 }
109}