Change tests to use either the inline or the multibulk protocol

This commit is contained in:
Pieter Noordhuis 2010-10-15 17:25:20 +02:00
parent 5b12b47df9
commit dc11daf3b5
4 changed files with 58 additions and 51 deletions

View File

@ -172,7 +172,7 @@ start_server {tags {"basic"}} {
test {Commands pipelining} {
set fd [r channel]
puts -nonewline $fd "SET k1 4\r\nxyzk\r\nGET k1\r\nPING\r\n"
puts -nonewline $fd "SET k1 xyzk\r\nGET k1\r\nPING\r\n"
flush $fd
set res {}
append res [string match OK* [::redis::redis_read_reply $fd]]

View File

@ -123,7 +123,7 @@ start_server {tags {"other"}} {
for {set i 0} {$i < 100000} {incr i} {
set q {}
set val "0000${i}0000"
append q "SET key:$i [string length $val]\r\n$val\r\n"
append q "SET key:$i $val\r\n"
puts -nonewline $fd2 $q
set q {}
append q "GET key:$i\r\n"

View File

@ -1,48 +1,55 @@
start_server {tags {"protocol"}} {
test {Handle an empty query well} {
set fd [r channel]
puts -nonewline $fd "\r\n"
flush $fd
r ping
} {PONG}
test "Handle an empty query" {
reconnect
r write "\r\n"
r flush
assert_equal "PONG" [r ping]
}
test {Negative multi bulk command does not create problems} {
set fd [r channel]
puts -nonewline $fd "*-10\r\n"
flush $fd
r ping
} {PONG}
test "Negative multibulk length" {
reconnect
r write "*-10\r\n"
r flush
assert_equal PONG [r ping]
}
test {Negative multi bulk payload} {
set fd [r channel]
puts -nonewline $fd "SET x -10\r\n"
flush $fd
gets $fd
} {*invalid bulk*}
test "Wrong multibulk payload header" {
reconnect
r write "*3\r\n\$3\r\nSET\r\n\$1\r\nx\r\nfooz\r\n"
r flush
assert_error "*expected '$', got 'f'*" {r read}
}
test {Too big bulk payload} {
set fd [r channel]
puts -nonewline $fd "SET x 2000000000\r\n"
flush $fd
gets $fd
} {*invalid bulk*count*}
test "Negative multibulk payload length" {
reconnect
r write "*3\r\n\$3\r\nSET\r\n\$1\r\nx\r\n\$-10\r\n"
r flush
assert_error "*invalid bulk length*" {r read}
}
test {bulk payload is not a number} {
set fd [r channel]
puts -nonewline $fd "SET x blabla\r\n"
flush $fd
gets $fd
} {*invalid bulk*count*}
test "Out of range multibulk payload length" {
reconnect
r write "*3\r\n\$3\r\nSET\r\n\$1\r\nx\r\n\$2000000000\r\n"
r flush
assert_error "*invalid bulk length*" {r read}
}
test {Multi bulk request not followed by bulk args} {
set fd [r channel]
puts -nonewline $fd "*1\r\nfoo\r\n"
flush $fd
gets $fd
} {*protocol error*}
test "Non-number multibulk payload length" {
reconnect
r write "*3\r\n\$3\r\nSET\r\n\$1\r\nx\r\n\$blabla\r\n"
r flush
assert_error "*invalid bulk length*" {r read}
}
test {Generic wrong number of args} {
catch {r ping x y z} err
set _ $err
} {*wrong*arguments*ping*}
test "Multi bulk request not followed by bulk arguments" {
reconnect
r write "*1\r\nfoo\r\n"
r flush
assert_error "*expected '$', got 'f'*" {r read}
}
test "Generic wrong number of args" {
reconnect
assert_error "*wrong*arguments*ping*" {r ping x y z}
}
}

View File

@ -47,11 +47,11 @@ start_server {
assert_encoding $enc tosort
test "$title: SORT BY key" {
assert_equal $result [r sort tosort {BY weight_*}]
assert_equal $result [r sort tosort BY weight_*]
}
test "$title: SORT BY hash field" {
assert_equal $result [r sort tosort {BY wobj_*->weight}]
assert_equal $result [r sort tosort BY wobj_*->weight]
}
}
@ -78,21 +78,21 @@ start_server {
}
test "SORT BY key STORE" {
r sort tosort {BY weight_*} store sort-res
r sort tosort BY weight_* store sort-res
assert_equal $result [r lrange sort-res 0 -1]
assert_equal 16 [r llen sort-res]
assert_encoding ziplist sort-res
}
test "SORT BY hash field STORE" {
r sort tosort {BY wobj_*->weight} store sort-res
r sort tosort BY wobj_*->weight store sort-res
assert_equal $result [r lrange sort-res 0 -1]
assert_equal 16 [r llen sort-res]
assert_encoding ziplist sort-res
}
test "SORT DESC" {
assert_equal [lsort -decreasing -integer $result] [r sort tosort {DESC}]
assert_equal [lsort -decreasing -integer $result] [r sort tosort DESC]
}
test "SORT ALPHA against integer encoded strings" {
@ -141,7 +141,7 @@ start_server {
test "SORT speed, $num element list BY key, 100 times" {
set start [clock clicks -milliseconds]
for {set i 0} {$i < 100} {incr i} {
set sorted [r sort tosort {BY weight_* LIMIT 0 10}]
set sorted [r sort tosort BY weight_* LIMIT 0 10]
}
set elapsed [expr [clock clicks -milliseconds]-$start]
puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
@ -151,7 +151,7 @@ start_server {
test "SORT speed, $num element list BY hash field, 100 times" {
set start [clock clicks -milliseconds]
for {set i 0} {$i < 100} {incr i} {
set sorted [r sort tosort {BY wobj_*->weight LIMIT 0 10}]
set sorted [r sort tosort BY wobj_*->weight LIMIT 0 10]
}
set elapsed [expr [clock clicks -milliseconds]-$start]
puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
@ -161,7 +161,7 @@ start_server {
test "SORT speed, $num element list directly, 100 times" {
set start [clock clicks -milliseconds]
for {set i 0} {$i < 100} {incr i} {
set sorted [r sort tosort {LIMIT 0 10}]
set sorted [r sort tosort LIMIT 0 10]
}
set elapsed [expr [clock clicks -milliseconds]-$start]
puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
@ -171,7 +171,7 @@ start_server {
test "SORT speed, $num element list BY <const>, 100 times" {
set start [clock clicks -milliseconds]
for {set i 0} {$i < 100} {incr i} {
set sorted [r sort tosort {BY nokey LIMIT 0 10}]
set sorted [r sort tosort BY nokey LIMIT 0 10]
}
set elapsed [expr [clock clicks -milliseconds]-$start]
puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "