mirror of
https://github.com/fluencelabs/redis
synced 2025-04-01 15:21:03 +00:00
refactor list tests to test both encodings; implemented assert functions
This commit is contained in:
parent
d1578a33ee
commit
d4507ec615
@ -2,7 +2,38 @@ set ::passed 0
|
|||||||
set ::failed 0
|
set ::failed 0
|
||||||
set ::testnum 0
|
set ::testnum 0
|
||||||
|
|
||||||
proc test {name code okpattern} {
|
proc assert_match {pattern value} {
|
||||||
|
if {![string match $pattern $value]} {
|
||||||
|
puts "!! ERROR\nExpected '$value' to match '$pattern'"
|
||||||
|
error "assertion"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
proc assert_equal {expected value} {
|
||||||
|
if {$expected ne $value} {
|
||||||
|
puts "!! ERROR\nExpected '$value' to be equal to '$expected'"
|
||||||
|
error "assertion"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
proc assert_error {pattern code} {
|
||||||
|
if {[catch $code error]} {
|
||||||
|
assert_match $pattern $error
|
||||||
|
} else {
|
||||||
|
puts "!! ERROR\nExpected an error but nothing was catched"
|
||||||
|
error "assertion"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
proc assert_encoding {enc key} {
|
||||||
|
assert_match "* encoding:$enc *" [r debug object $key]
|
||||||
|
}
|
||||||
|
|
||||||
|
proc assert_type {type key} {
|
||||||
|
assert_equal $type [r type $key]
|
||||||
|
}
|
||||||
|
|
||||||
|
proc test {name code {okpattern notspecified}} {
|
||||||
# abort if tagged with a tag to deny
|
# abort if tagged with a tag to deny
|
||||||
foreach tag $::denytags {
|
foreach tag $::denytags {
|
||||||
if {[lsearch $::tags $tag] >= 0} {
|
if {[lsearch $::tags $tag] >= 0} {
|
||||||
@ -28,16 +59,21 @@ proc test {name code okpattern} {
|
|||||||
puts -nonewline [format "#%03d %-68s " $::testnum $name]
|
puts -nonewline [format "#%03d %-68s " $::testnum $name]
|
||||||
flush stdout
|
flush stdout
|
||||||
if {[catch {set retval [uplevel 1 $code]} error]} {
|
if {[catch {set retval [uplevel 1 $code]} error]} {
|
||||||
puts "EXCEPTION"
|
if {$error eq "assertion"} {
|
||||||
puts "\nCaught error: $error"
|
incr ::failed
|
||||||
error "exception"
|
} else {
|
||||||
}
|
puts "EXCEPTION"
|
||||||
if {$okpattern eq $retval || [string match $okpattern $retval]} {
|
puts "\nCaught error: $error"
|
||||||
puts "PASSED"
|
error "exception"
|
||||||
incr ::passed
|
}
|
||||||
} else {
|
} else {
|
||||||
puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
|
if {$okpattern eq "notspecified" || $okpattern eq $retval || [string match $okpattern $retval]} {
|
||||||
incr ::failed
|
puts "PASSED"
|
||||||
|
incr ::passed
|
||||||
|
} else {
|
||||||
|
puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
|
||||||
|
incr ::failed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if {$::traceleaks} {
|
if {$::traceleaks} {
|
||||||
if {![string match {*0 leaks*} [exec leaks redis-server]]} {
|
if {![string match {*0 leaks*} [exec leaks redis-server]]} {
|
||||||
|
@ -73,7 +73,7 @@ proc main {} {
|
|||||||
execute_tests "integration/aof"
|
execute_tests "integration/aof"
|
||||||
|
|
||||||
# run tests with VM enabled
|
# run tests with VM enabled
|
||||||
set ::global_overrides [list [list vm-enabled yes]]
|
set ::global_overrides {vm-enabled yes}
|
||||||
execute_tests "unit/protocol"
|
execute_tests "unit/protocol"
|
||||||
execute_tests "unit/basic"
|
execute_tests "unit/basic"
|
||||||
execute_tests "unit/type/list"
|
execute_tests "unit/type/list"
|
||||||
|
@ -1,221 +1,345 @@
|
|||||||
start_server {tags {"list"}} {
|
start_server {
|
||||||
test {Basic LPUSH, RPUSH, LLENGTH, LINDEX} {
|
tags {"list"}
|
||||||
set res [r lpush mylist a]
|
overrides {
|
||||||
append res [r lpush mylist b]
|
"list-max-ziplist-value" 16
|
||||||
append res [r rpush mylist c]
|
"list-max-ziplist-entries" 256
|
||||||
append res [r llen mylist]
|
}
|
||||||
append res [r rpush anotherlist d]
|
} {
|
||||||
append res [r lpush anotherlist e]
|
test {LPUSH, RPUSH, LLENGTH, LINDEX - ziplist} {
|
||||||
append res [r llen anotherlist]
|
# first lpush then rpush
|
||||||
append res [r lindex mylist 0]
|
assert_equal 1 [r lpush myziplist1 a]
|
||||||
append res [r lindex mylist 1]
|
assert_equal 2 [r rpush myziplist1 b]
|
||||||
append res [r lindex mylist 2]
|
assert_equal 3 [r rpush myziplist1 c]
|
||||||
append res [r lindex anotherlist 0]
|
assert_equal 3 [r llen myziplist1]
|
||||||
append res [r lindex anotherlist 1]
|
assert_equal a [r lindex myziplist1 0]
|
||||||
list $res [r lindex mylist 100]
|
assert_equal b [r lindex myziplist1 1]
|
||||||
} {1233122baced {}}
|
assert_equal c [r lindex myziplist1 2]
|
||||||
|
assert_encoding ziplist myziplist1
|
||||||
|
|
||||||
test {DEL a list} {
|
# first rpush then lpush
|
||||||
r del mylist
|
assert_equal 1 [r rpush myziplist2 a]
|
||||||
r exists mylist
|
assert_equal 2 [r lpush myziplist2 b]
|
||||||
} {0}
|
assert_equal 3 [r lpush myziplist2 c]
|
||||||
|
assert_equal 3 [r llen myziplist2]
|
||||||
|
assert_equal c [r lindex myziplist2 0]
|
||||||
|
assert_equal b [r lindex myziplist2 1]
|
||||||
|
assert_equal a [r lindex myziplist2 2]
|
||||||
|
assert_encoding ziplist myziplist2
|
||||||
|
}
|
||||||
|
|
||||||
test {Create a long list and check every single element with LINDEX} {
|
test {LPUSH, RPUSH, LLENGTH, LINDEX - regular list} {
|
||||||
set ok 0
|
# use a string of length 17 to ensure a regular list is used
|
||||||
for {set i 0} {$i < 1000} {incr i} {
|
set large_value "aaaaaaaaaaaaaaaaa"
|
||||||
r rpush mylist $i
|
|
||||||
|
# first lpush then rpush
|
||||||
|
assert_equal 1 [r lpush mylist1 $large_value]
|
||||||
|
assert_encoding list mylist1
|
||||||
|
assert_equal 2 [r rpush mylist1 b]
|
||||||
|
assert_equal 3 [r rpush mylist1 c]
|
||||||
|
assert_equal 3 [r llen mylist1]
|
||||||
|
assert_equal $large_value [r lindex mylist1 0]
|
||||||
|
assert_equal b [r lindex mylist1 1]
|
||||||
|
assert_equal c [r lindex mylist1 2]
|
||||||
|
|
||||||
|
# first rpush then lpush
|
||||||
|
assert_equal 1 [r rpush mylist2 $large_value]
|
||||||
|
assert_encoding list mylist2
|
||||||
|
assert_equal 2 [r lpush mylist2 b]
|
||||||
|
assert_equal 3 [r lpush mylist2 c]
|
||||||
|
assert_equal 3 [r llen mylist2]
|
||||||
|
assert_equal c [r lindex mylist2 0]
|
||||||
|
assert_equal b [r lindex mylist2 1]
|
||||||
|
assert_equal $large_value [r lindex mylist2 2]
|
||||||
|
}
|
||||||
|
|
||||||
|
test {DEL a list - ziplist} {
|
||||||
|
assert_equal 1 [r del myziplist2]
|
||||||
|
assert_equal 0 [r exists myziplist2]
|
||||||
|
assert_equal 0 [r llen myziplist2]
|
||||||
|
}
|
||||||
|
|
||||||
|
test {DEL a list - regular list} {
|
||||||
|
assert_equal 1 [r del mylist2]
|
||||||
|
assert_equal 0 [r exists mylist2]
|
||||||
|
assert_equal 0 [r llen mylist2]
|
||||||
|
}
|
||||||
|
|
||||||
|
proc populate_with_numbers {key num} {
|
||||||
|
for {set i 0} {$i < $num} {incr i} {
|
||||||
|
r rpush $key $i
|
||||||
}
|
}
|
||||||
for {set i 0} {$i < 1000} {incr i} {
|
}
|
||||||
if {[r lindex mylist $i] eq $i} {incr ok}
|
|
||||||
if {[r lindex mylist [expr (-$i)-1]] eq [expr 999-$i]} {
|
|
||||||
incr ok
|
|
||||||
}
|
|
||||||
}
|
|
||||||
format $ok
|
|
||||||
} {2000}
|
|
||||||
|
|
||||||
test {Test elements with LINDEX in random access} {
|
proc check_numbered_list_consistency {key} {
|
||||||
set ok 0
|
set len [r llen $key]
|
||||||
for {set i 0} {$i < 1000} {incr i} {
|
for {set i 0} {$i < $len} {incr i} {
|
||||||
set rint [expr int(rand()*1000)]
|
assert_equal $i [r lindex $key $i]
|
||||||
if {[r lindex mylist $rint] eq $rint} {incr ok}
|
assert_equal [expr $len-1-$i] [r lindex $key [expr (-$i)-1]]
|
||||||
if {[r lindex mylist [expr (-$rint)-1]] eq [expr 999-$rint]} {
|
|
||||||
incr ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
format $ok
|
}
|
||||||
} {2000}
|
|
||||||
|
|
||||||
test {Check if the list is still ok after a DEBUG RELOAD} {
|
proc check_random_access_consistency {key} {
|
||||||
|
set len [r llen $key]
|
||||||
|
for {set i 0} {$i < $len} {incr i} {
|
||||||
|
set rint [expr int(rand()*$len)]
|
||||||
|
assert_equal $rint [r lindex $key $rint]
|
||||||
|
assert_equal [expr $len-1-$rint] [r lindex $key [expr (-$rint)-1]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test {LINDEX consistency test - ziplist} {
|
||||||
|
populate_with_numbers myziplist 250
|
||||||
|
assert_encoding ziplist myziplist
|
||||||
|
}
|
||||||
|
|
||||||
|
test {LINDEX consistency test - regular list} {
|
||||||
|
populate_with_numbers mylist 500
|
||||||
|
assert_encoding list mylist
|
||||||
|
check_numbered_list_consistency mylist
|
||||||
|
}
|
||||||
|
|
||||||
|
test {LINDEX random access - ziplist} {
|
||||||
|
assert_encoding ziplist myziplist
|
||||||
|
check_random_access_consistency myziplist
|
||||||
|
}
|
||||||
|
|
||||||
|
test {LINDEX random access - regular list} {
|
||||||
|
assert_encoding list mylist
|
||||||
|
check_random_access_consistency mylist
|
||||||
|
}
|
||||||
|
|
||||||
|
test {Check if both list encodings are still ok after a DEBUG RELOAD} {
|
||||||
r debug reload
|
r debug reload
|
||||||
set ok 0
|
assert_encoding ziplist myziplist
|
||||||
for {set i 0} {$i < 1000} {incr i} {
|
check_numbered_list_consistency myziplist
|
||||||
set rint [expr int(rand()*1000)]
|
assert_encoding list mylist
|
||||||
if {[r lindex mylist $rint] eq $rint} {incr ok}
|
check_numbered_list_consistency mylist
|
||||||
if {[r lindex mylist [expr (-$rint)-1]] eq [expr 999-$rint]} {
|
}
|
||||||
incr ok
|
|
||||||
}
|
|
||||||
}
|
|
||||||
format $ok
|
|
||||||
} {2000}
|
|
||||||
|
|
||||||
test {LLEN against non-list value error} {
|
test {LLEN against non-list value error} {
|
||||||
r del mylist
|
r del mylist
|
||||||
r set mylist foobar
|
r set mylist foobar
|
||||||
catch {r llen mylist} err
|
assert_error ERR* {r llen mylist}
|
||||||
format $err
|
}
|
||||||
} {ERR*}
|
|
||||||
|
|
||||||
test {LLEN against non existing key} {
|
test {LLEN against non existing key} {
|
||||||
r llen not-a-key
|
assert_equal 0 [r llen not-a-key]
|
||||||
} {0}
|
}
|
||||||
|
|
||||||
test {LINDEX against non-list value error} {
|
test {LINDEX against non-list value error} {
|
||||||
catch {r lindex mylist 0} err
|
assert_error ERR* {r lindex mylist 0}
|
||||||
format $err
|
}
|
||||||
} {ERR*}
|
|
||||||
|
|
||||||
test {LINDEX against non existing key} {
|
test {LINDEX against non existing key} {
|
||||||
r lindex not-a-key 10
|
assert_equal "" [r lindex not-a-key 10]
|
||||||
} {}
|
}
|
||||||
|
|
||||||
test {LPUSH against non-list value error} {
|
test {LPUSH against non-list value error} {
|
||||||
catch {r lpush mylist 0} err
|
assert_error ERR* {r lpush mylist 0}
|
||||||
format $err
|
}
|
||||||
} {ERR*}
|
|
||||||
|
|
||||||
test {RPUSH against non-list value error} {
|
test {RPUSH against non-list value error} {
|
||||||
catch {r rpush mylist 0} err
|
assert_error ERR* {r rpush mylist 0}
|
||||||
format $err
|
}
|
||||||
} {ERR*}
|
|
||||||
|
|
||||||
test {RPOPLPUSH base case} {
|
proc create_ziplist {key entries} {
|
||||||
r del mylist
|
r del $key
|
||||||
r rpush mylist a
|
foreach entry $entries { r rpush $key $entry }
|
||||||
r rpush mylist b
|
assert_match *encoding:ziplist* [r debug object $key]
|
||||||
r rpush mylist c
|
}
|
||||||
r rpush mylist d
|
|
||||||
set v1 [r rpoplpush mylist newlist]
|
|
||||||
set v2 [r rpoplpush mylist newlist]
|
|
||||||
set l1 [r lrange mylist 0 -1]
|
|
||||||
set l2 [r lrange newlist 0 -1]
|
|
||||||
list $v1 $v2 $l1 $l2
|
|
||||||
} {d c {a b} {c d}}
|
|
||||||
|
|
||||||
test {RPOPLPUSH with the same list as src and dst} {
|
proc create_regular_list {key entries} {
|
||||||
r del mylist
|
r del $key
|
||||||
r rpush mylist a
|
r rpush $key "aaaaaaaaaaaaaaaaa"
|
||||||
r rpush mylist b
|
foreach entry $entries { r rpush $key $entry }
|
||||||
r rpush mylist c
|
assert_equal "aaaaaaaaaaaaaaaaa" [r lpop $key]
|
||||||
set l1 [r lrange mylist 0 -1]
|
assert_match *encoding:list* [r debug object $key]
|
||||||
set v [r rpoplpush mylist mylist]
|
}
|
||||||
set l2 [r lrange mylist 0 -1]
|
|
||||||
list $l1 $v $l2
|
|
||||||
} {{a b c} c {c a b}}
|
|
||||||
|
|
||||||
test {RPOPLPUSH target list already exists} {
|
test {RPOPLPUSH base case - ziplist} {
|
||||||
r del mylist
|
r del mylist1 mylist2
|
||||||
r del newlist
|
create_ziplist mylist1 {a b c d}
|
||||||
r rpush mylist a
|
assert_equal d [r rpoplpush mylist1 mylist2]
|
||||||
r rpush mylist b
|
assert_equal c [r rpoplpush mylist1 mylist2]
|
||||||
r rpush mylist c
|
assert_equal {a b} [r lrange mylist1 0 -1]
|
||||||
r rpush mylist d
|
assert_equal {c d} [r lrange mylist2 0 -1]
|
||||||
r rpush newlist x
|
assert_encoding ziplist mylist2
|
||||||
set v1 [r rpoplpush mylist newlist]
|
}
|
||||||
set v2 [r rpoplpush mylist newlist]
|
|
||||||
set l1 [r lrange mylist 0 -1]
|
test {RPOPLPUSH base case - regular list} {
|
||||||
set l2 [r lrange newlist 0 -1]
|
r del mylist1 mylist2
|
||||||
list $v1 $v2 $l1 $l2
|
create_regular_list mylist1 {a b c d}
|
||||||
} {d c {a b} {c d x}}
|
assert_equal d [r rpoplpush mylist1 mylist2]
|
||||||
|
assert_equal c [r rpoplpush mylist1 mylist2]
|
||||||
|
assert_equal {a b} [r lrange mylist1 0 -1]
|
||||||
|
assert_equal {c d} [r lrange mylist2 0 -1]
|
||||||
|
assert_encoding ziplist mylist2
|
||||||
|
}
|
||||||
|
|
||||||
|
test {RPOPLPUSH with the same list as src and dst - ziplist} {
|
||||||
|
create_ziplist myziplist {a b c}
|
||||||
|
assert_equal {a b c} [r lrange myziplist 0 -1]
|
||||||
|
assert_equal c [r rpoplpush myziplist myziplist]
|
||||||
|
assert_equal {c a b} [r lrange myziplist 0 -1]
|
||||||
|
}
|
||||||
|
|
||||||
|
test {RPOPLPUSH with the same list as src and dst - regular list} {
|
||||||
|
create_regular_list mylist {a b c}
|
||||||
|
assert_equal {a b c} [r lrange mylist 0 -1]
|
||||||
|
assert_equal c [r rpoplpush mylist mylist]
|
||||||
|
assert_equal {c a b} [r lrange mylist 0 -1]
|
||||||
|
}
|
||||||
|
|
||||||
|
test {RPOPLPUSH target list already exists, being a ziplist} {
|
||||||
|
create_regular_list srclist {a b c d}
|
||||||
|
create_ziplist dstlist {x}
|
||||||
|
assert_equal d [r rpoplpush srclist dstlist]
|
||||||
|
assert_equal c [r rpoplpush srclist dstlist]
|
||||||
|
assert_equal {a b} [r lrange srclist 0 -1]
|
||||||
|
assert_equal {c d x} [r lrange dstlist 0 -1]
|
||||||
|
}
|
||||||
|
|
||||||
|
test {RPOPLPUSH target list already exists, being a regular list} {
|
||||||
|
create_regular_list srclist {a b c d}
|
||||||
|
create_regular_list dstlist {x}
|
||||||
|
assert_equal d [r rpoplpush srclist dstlist]
|
||||||
|
assert_equal c [r rpoplpush srclist dstlist]
|
||||||
|
assert_equal {a b} [r lrange srclist 0 -1]
|
||||||
|
assert_equal {c d x} [r lrange dstlist 0 -1]
|
||||||
|
}
|
||||||
|
|
||||||
test {RPOPLPUSH against non existing key} {
|
test {RPOPLPUSH against non existing key} {
|
||||||
r del mylist
|
r del srclist dstlist
|
||||||
r del newlist
|
assert_equal {} [r rpoplpush srclist dstlist]
|
||||||
set v1 [r rpoplpush mylist newlist]
|
assert_equal 0 [r exists srclist]
|
||||||
list $v1 [r exists mylist] [r exists newlist]
|
assert_equal 0 [r exists dstlist]
|
||||||
} {{} 0 0}
|
}
|
||||||
|
|
||||||
test {RPOPLPUSH against non list src key} {
|
test {RPOPLPUSH against non list src key} {
|
||||||
r del mylist
|
r del srclist dstlist
|
||||||
r del newlist
|
r set srclist x
|
||||||
r set mylist x
|
assert_error ERR* {r rpoplpush srclist dstlist}
|
||||||
catch {r rpoplpush mylist newlist} err
|
assert_type string srclist
|
||||||
list [r type mylist] [r exists newlist] [string range $err 0 2]
|
assert_equal 0 [r exists newlist]
|
||||||
} {string 0 ERR}
|
}
|
||||||
|
|
||||||
test {RPOPLPUSH against non list dst key} {
|
test {RPOPLPUSH against non list dst key} {
|
||||||
r del mylist
|
create_ziplist srclist {a b c d}
|
||||||
r del newlist
|
r set dstlist x
|
||||||
r rpush mylist a
|
assert_error ERR* {r rpoplpush srclist dstlist}
|
||||||
r rpush mylist b
|
assert_type string dstlist
|
||||||
r rpush mylist c
|
assert_equal {a b c d} [r lrange srclist 0 -1]
|
||||||
r rpush mylist d
|
}
|
||||||
r set newlist x
|
|
||||||
catch {r rpoplpush mylist newlist} err
|
|
||||||
list [r lrange mylist 0 -1] [r type newlist] [string range $err 0 2]
|
|
||||||
} {{a b c d} string ERR}
|
|
||||||
|
|
||||||
test {RPOPLPUSH against non existing src key} {
|
test {RPOPLPUSH against non existing src key} {
|
||||||
r del mylist
|
r del srclist dstlist
|
||||||
r del newlist
|
assert_equal {} [r rpoplpush srclist dstlist]
|
||||||
r rpoplpush mylist newlist
|
|
||||||
} {}
|
|
||||||
|
|
||||||
test {Basic LPOP/RPOP} {
|
|
||||||
r del mylist
|
|
||||||
r rpush mylist 1
|
|
||||||
r rpush mylist 2
|
|
||||||
r lpush mylist 0
|
|
||||||
list [r lpop mylist] [r rpop mylist] [r lpop mylist] [r llen mylist]
|
|
||||||
} [list 0 2 1 0]
|
|
||||||
|
|
||||||
test {LPOP/RPOP against empty list} {
|
|
||||||
r lpop mylist
|
|
||||||
} {}
|
} {}
|
||||||
|
|
||||||
test {LPOP against non list value} {
|
test {Basic LPOP/RPOP - ziplist} {
|
||||||
|
create_ziplist myziplist {0 1 2}
|
||||||
|
assert_equal 0 [r lpop myziplist]
|
||||||
|
assert_equal 2 [r rpop myziplist]
|
||||||
|
assert_equal 1 [r lpop myziplist]
|
||||||
|
assert_equal 0 [r llen myziplist]
|
||||||
|
|
||||||
|
# pop on empty list
|
||||||
|
assert_equal {} [r lpop myziplist]
|
||||||
|
assert_equal {} [r rpop myziplist]
|
||||||
|
}
|
||||||
|
|
||||||
|
test {Basic LPOP/RPOP - regular list} {
|
||||||
|
create_regular_list mylist {0 1 2}
|
||||||
|
assert_equal 0 [r lpop mylist]
|
||||||
|
assert_equal 2 [r rpop mylist]
|
||||||
|
assert_equal 1 [r lpop mylist]
|
||||||
|
assert_equal 0 [r llen mylist]
|
||||||
|
|
||||||
|
# pop on empty list
|
||||||
|
assert_equal {} [r lpop mylist]
|
||||||
|
assert_equal {} [r rpop mylist]
|
||||||
|
}
|
||||||
|
|
||||||
|
test {LPOP/RPOP against non list value} {
|
||||||
r set notalist foo
|
r set notalist foo
|
||||||
catch {r lpop notalist} err
|
assert_error ERR*kind* {r lpop notalist}
|
||||||
format $err
|
assert_error ERR*kind* {r rpop notalist}
|
||||||
} {ERR*kind*}
|
}
|
||||||
|
|
||||||
test {Mass LPUSH/LPOP} {
|
test {Mass RPOP/LPOP - ziplist} {
|
||||||
set sum 0
|
r del mylist
|
||||||
for {set i 0} {$i < 1000} {incr i} {
|
set sum1 0
|
||||||
|
for {set i 0} {$i < 250} {incr i} {
|
||||||
r lpush mylist $i
|
r lpush mylist $i
|
||||||
incr sum $i
|
incr sum1 $i
|
||||||
}
|
}
|
||||||
|
assert_encoding ziplist mylist
|
||||||
set sum2 0
|
set sum2 0
|
||||||
for {set i 0} {$i < 500} {incr i} {
|
for {set i 0} {$i < 125} {incr i} {
|
||||||
incr sum2 [r lpop mylist]
|
incr sum2 [r lpop mylist]
|
||||||
incr sum2 [r rpop mylist]
|
incr sum2 [r rpop mylist]
|
||||||
}
|
}
|
||||||
expr $sum == $sum2
|
assert_equal $sum1 $sum2
|
||||||
} {1}
|
}
|
||||||
|
|
||||||
test {LRANGE basics} {
|
test {Mass RPOP/LPOP - regular list} {
|
||||||
for {set i 0} {$i < 10} {incr i} {
|
r del mylist
|
||||||
r rpush mylist $i
|
set sum1 0
|
||||||
|
for {set i 0} {$i < 500} {incr i} {
|
||||||
|
r lpush mylist $i
|
||||||
|
incr sum1 $i
|
||||||
}
|
}
|
||||||
list [r lrange mylist 1 -2] \
|
assert_encoding list mylist
|
||||||
[r lrange mylist -3 -1] \
|
set sum2 0
|
||||||
[r lrange mylist 4 4]
|
for {set i 0} {$i < 250} {incr i} {
|
||||||
} {{1 2 3 4 5 6 7 8} {7 8 9} 4}
|
incr sum2 [r lpop mylist]
|
||||||
|
incr sum2 [r rpop mylist]
|
||||||
|
}
|
||||||
|
assert_equal $sum1 $sum2
|
||||||
|
}
|
||||||
|
|
||||||
test {LRANGE inverted indexes} {
|
test {LRANGE basics - ziplist} {
|
||||||
r lrange mylist 6 2
|
create_ziplist mylist {0 1 2 3 4 5 6 7 8 9}
|
||||||
} {}
|
assert_equal {1 2 3 4 5 6 7 8} [r lrange mylist 1 -2]
|
||||||
|
assert_equal {7 8 9} [r lrange mylist -3 -1]
|
||||||
|
assert_equal {4} [r lrange mylist 4 4]
|
||||||
|
}
|
||||||
|
|
||||||
test {LRANGE out of range indexes including the full list} {
|
test {LRANGE basics - ziplist} {
|
||||||
r lrange mylist -1000 1000
|
create_regular_list mylist {0 1 2 3 4 5 6 7 8 9}
|
||||||
} {0 1 2 3 4 5 6 7 8 9}
|
assert_equal {1 2 3 4 5 6 7 8} [r lrange mylist 1 -2]
|
||||||
|
assert_equal {7 8 9} [r lrange mylist -3 -1]
|
||||||
|
assert_equal {4} [r lrange mylist 4 4]
|
||||||
|
}
|
||||||
|
|
||||||
|
test {LRANGE inverted indexes - ziplist} {
|
||||||
|
create_ziplist mylist {0 1 2 3 4 5 6 7 8 9}
|
||||||
|
assert_equal {} [r lrange mylist 6 2]
|
||||||
|
}
|
||||||
|
|
||||||
|
test {LRANGE inverted indexes - regular list} {
|
||||||
|
create_regular_list mylist {0 1 2 3 4 5 6 7 8 9}
|
||||||
|
assert_equal {} [r lrange mylist 6 2]
|
||||||
|
}
|
||||||
|
|
||||||
|
test {LRANGE out of range indexes including the full list - ziplist} {
|
||||||
|
create_ziplist mylist {1 2 3}
|
||||||
|
assert_equal {1 2 3} [r lrange mylist -1000 1000]
|
||||||
|
}
|
||||||
|
|
||||||
|
test {LRANGE out of range indexes including the full list - regular list} {
|
||||||
|
create_regular_list mylist {1 2 3}
|
||||||
|
assert_equal {1 2 3} [r lrange mylist -1000 1000]
|
||||||
|
}
|
||||||
|
|
||||||
test {LRANGE against non existing key} {
|
test {LRANGE against non existing key} {
|
||||||
r lrange nosuchkey 0 1
|
assert_equal {} [r lrange nosuchkey 0 1]
|
||||||
} {}
|
}
|
||||||
|
|
||||||
test {LTRIM basics} {
|
test {LTRIM basics - ziplist} {
|
||||||
r del mylist
|
r del mylist
|
||||||
|
r lpush mylist "aaa"
|
||||||
|
assert_encoding ziplist mylist
|
||||||
for {set i 0} {$i < 100} {incr i} {
|
for {set i 0} {$i < 100} {incr i} {
|
||||||
r lpush mylist $i
|
r lpush mylist $i
|
||||||
r ltrim mylist 0 4
|
r ltrim mylist 0 4
|
||||||
@ -223,106 +347,114 @@ start_server {tags {"list"}} {
|
|||||||
r lrange mylist 0 -1
|
r lrange mylist 0 -1
|
||||||
} {99 98 97 96 95}
|
} {99 98 97 96 95}
|
||||||
|
|
||||||
test {LTRIM stress testing} {
|
test {LTRIM basics - regular list} {
|
||||||
|
r del mylist
|
||||||
|
r lpush mylist "aaaaaaaaaaaaaaaaa"
|
||||||
|
assert_encoding list mylist
|
||||||
|
for {set i 0} {$i < 100} {incr i} {
|
||||||
|
r lpush mylist $i
|
||||||
|
r ltrim mylist 0 4
|
||||||
|
}
|
||||||
|
r lrange mylist 0 -1
|
||||||
|
} {99 98 97 96 95}
|
||||||
|
|
||||||
|
test {LTRIM stress testing - ziplist} {
|
||||||
set mylist {}
|
set mylist {}
|
||||||
set err {}
|
|
||||||
for {set i 0} {$i < 20} {incr i} {
|
for {set i 0} {$i < 20} {incr i} {
|
||||||
lappend mylist $i
|
lappend mylist $i
|
||||||
}
|
}
|
||||||
|
|
||||||
for {set j 0} {$j < 100} {incr j} {
|
for {set j 0} {$j < 100} {incr j} {
|
||||||
# Fill the list
|
create_ziplist mylist $mylist
|
||||||
r del mylist
|
|
||||||
for {set i 0} {$i < 20} {incr i} {
|
|
||||||
r rpush mylist $i
|
|
||||||
}
|
|
||||||
# Trim at random
|
# Trim at random
|
||||||
set a [randomInt 20]
|
set a [randomInt 20]
|
||||||
set b [randomInt 20]
|
set b [randomInt 20]
|
||||||
r ltrim mylist $a $b
|
r ltrim mylist $a $b
|
||||||
if {[r lrange mylist 0 -1] ne [lrange $mylist $a $b]} {
|
assert_equal [lrange $mylist $a $b] [r lrange mylist 0 -1]
|
||||||
set err "[r lrange mylist 0 -1] != [lrange $mylist $a $b]"
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
set _ $err
|
}
|
||||||
} {}
|
|
||||||
|
|
||||||
test {LSET} {
|
test {LTRIM stress testing - regular list} {
|
||||||
r del mylist
|
set mylist {}
|
||||||
foreach x {99 98 97 96 95} {
|
for {set i 0} {$i < 20} {incr i} {
|
||||||
r rpush mylist $x
|
lappend mylist $i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for {set j 0} {$j < 100} {incr j} {
|
||||||
|
create_regular_list mylist $mylist
|
||||||
|
# Trim at random
|
||||||
|
set a [randomInt 20]
|
||||||
|
set b [randomInt 20]
|
||||||
|
r ltrim mylist $a $b
|
||||||
|
assert_equal [lrange $mylist $a $b] [r lrange mylist 0 -1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test {LSET - ziplist} {
|
||||||
|
create_ziplist mylist {99 98 97 96 95}
|
||||||
r lset mylist 1 foo
|
r lset mylist 1 foo
|
||||||
r lset mylist -1 bar
|
r lset mylist -1 bar
|
||||||
r lrange mylist 0 -1
|
assert_equal {99 foo 97 96 bar} [r lrange mylist 0 -1]
|
||||||
} {99 foo 97 96 bar}
|
}
|
||||||
|
|
||||||
test {LSET out of range index} {
|
test {LSET out of range index - ziplist} {
|
||||||
catch {r lset mylist 10 foo} err
|
assert_error ERR*range* {r lset mylist 10 foo}
|
||||||
format $err
|
}
|
||||||
} {ERR*range*}
|
|
||||||
|
test {LSET - regular list} {
|
||||||
|
create_regular_list mylist {99 98 97 96 95}
|
||||||
|
r lset mylist 1 foo
|
||||||
|
r lset mylist -1 bar
|
||||||
|
assert_equal {99 foo 97 96 bar} [r lrange mylist 0 -1]
|
||||||
|
}
|
||||||
|
|
||||||
|
test {LSET out of range index - regular list} {
|
||||||
|
assert_error ERR*range* {r lset mylist 10 foo}
|
||||||
|
}
|
||||||
|
|
||||||
test {LSET against non existing key} {
|
test {LSET against non existing key} {
|
||||||
catch {r lset nosuchkey 10 foo} err
|
assert_error ERR*key* {r lset nosuchkey 10 foo}
|
||||||
format $err
|
}
|
||||||
} {ERR*key*}
|
|
||||||
|
|
||||||
test {LSET against non list value} {
|
test {LSET against non list value} {
|
||||||
r set nolist foobar
|
r set nolist foobar
|
||||||
catch {r lset nolist 0 foo} err
|
assert_error ERR*value* {r lset nolist 0 foo}
|
||||||
format $err
|
}
|
||||||
} {ERR*value*}
|
|
||||||
|
|
||||||
test {LREM, remove all the occurrences} {
|
|
||||||
r flushdb
|
|
||||||
r rpush mylist foo
|
|
||||||
r rpush mylist bar
|
|
||||||
r rpush mylist foobar
|
|
||||||
r rpush mylist foobared
|
|
||||||
r rpush mylist zap
|
|
||||||
r rpush mylist bar
|
|
||||||
r rpush mylist test
|
|
||||||
r rpush mylist foo
|
|
||||||
set res [r lrem mylist 0 bar]
|
|
||||||
list [r lrange mylist 0 -1] $res
|
|
||||||
} {{foo foobar foobared zap test foo} 2}
|
|
||||||
|
|
||||||
test {LREM, remove the first occurrence} {
|
foreach type {ziplist regular_list} {
|
||||||
set res [r lrem mylist 1 foo]
|
set formatted_type [string map {"_" " "} $type]
|
||||||
list [r lrange mylist 0 -1] $res
|
|
||||||
} {{foobar foobared zap test foo} 1}
|
|
||||||
|
|
||||||
test {LREM, remove non existing element} {
|
test "LREM remove all the occurrences - $formatted_type" {
|
||||||
set res [r lrem mylist 1 nosuchelement]
|
create_$type mylist {foo bar foobar foobared zap bar test foo}
|
||||||
list [r lrange mylist 0 -1] $res
|
assert_equal 2 [r lrem mylist 0 bar]
|
||||||
} {{foobar foobared zap test foo} 0}
|
assert_equal {foo foobar foobared zap test foo} [r lrange mylist 0 -1]
|
||||||
|
}
|
||||||
|
|
||||||
test {LREM, starting from tail with negative count} {
|
test "LREM remove the first occurrence - $formatted_type" {
|
||||||
r flushdb
|
assert_equal 1 [r lrem mylist 1 foo]
|
||||||
r rpush mylist foo
|
assert_equal {foobar foobared zap test foo} [r lrange mylist 0 -1]
|
||||||
r rpush mylist bar
|
}
|
||||||
r rpush mylist foobar
|
|
||||||
r rpush mylist foobared
|
|
||||||
r rpush mylist zap
|
|
||||||
r rpush mylist bar
|
|
||||||
r rpush mylist test
|
|
||||||
r rpush mylist foo
|
|
||||||
r rpush mylist foo
|
|
||||||
set res [r lrem mylist -1 bar]
|
|
||||||
list [r lrange mylist 0 -1] $res
|
|
||||||
} {{foo bar foobar foobared zap test foo foo} 1}
|
|
||||||
|
|
||||||
test {LREM, starting from tail with negative count (2)} {
|
test "LREM remove non existing element - $formatted_type" {
|
||||||
set res [r lrem mylist -2 foo]
|
assert_equal 0 [r lrem mylist 1 nosuchelement]
|
||||||
list [r lrange mylist 0 -1] $res
|
assert_equal {foobar foobared zap test foo} [r lrange mylist 0 -1]
|
||||||
} {{foo bar foobar foobared zap test} 2}
|
}
|
||||||
|
|
||||||
test {LREM, deleting objects that may be encoded as integers} {
|
test "LREM starting from tail with negative count - $formatted_type" {
|
||||||
r lpush myotherlist 1
|
create_$type mylist {foo bar foobar foobared zap bar test foo foo}
|
||||||
r lpush myotherlist 2
|
assert_equal 1 [r lrem mylist -1 bar]
|
||||||
r lpush myotherlist 3
|
assert_equal {foo bar foobar foobared zap test foo foo} [r lrange mylist 0 -1]
|
||||||
r lrem myotherlist 1 2
|
}
|
||||||
r llen myotherlist
|
|
||||||
} {2}
|
test "LREM starting from tail with negative count (2) - $formatted_type" {
|
||||||
|
assert_equal 2 [r lrem mylist -2 foo]
|
||||||
|
assert_equal {foo bar foobar foobared zap test} [r lrange mylist 0 -1]
|
||||||
|
}
|
||||||
|
|
||||||
|
test "LREM deleting objects that may be int encoded - $formatted_type" {
|
||||||
|
create_$type myotherlist {1 2 3}
|
||||||
|
assert_equal 1 [r lrem myotherlist 1 2]
|
||||||
|
assert_equal 2 [r llen myotherlist]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user