Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
ab193fe4
Commit
ab193fe4
authored
Jun 04, 2010
by
Pieter Noordhuis
Browse files
generated tests for different encodings to avoid test code duplication
parent
d4507ec6
Changes
1
Show whitespace changes
Inline
Side-by-side
tests/unit/type/list.tcl
View file @
ab193fe4
...
@@ -64,12 +64,21 @@ start_server {
...
@@ -64,12 +64,21 @@ start_server {
assert_equal 0
[
r llen mylist2
]
assert_equal 0
[
r llen mylist2
]
}
}
proc populate_with_numbers
{
key num
}
{
proc create_ziplist
{
key entries
}
{
for
{
set i 0
}
{
$i
< $num
}
{
incr i
}
{
r del $key
r rpush $key $i
foreach entry $entries
{
r rpush $key $entry
}
assert_encoding ziplist $key
}
}
proc create_list
{
key entries
}
{
r del $key
r rpush $key
"aaaaaaaaaaaaaaaaa"
foreach entry $entries
{
r rpush $key $entry
}
assert_equal
"aaaaaaaaaaaaaaaaa"
[
r lpop $key
]
assert_encoding list $key
}
}
foreach
{
type num
}
{
ziplist 250 list 500
}
{
proc check_numbered_list_consistency
{
key
}
{
proc check_numbered_list_consistency
{
key
}
{
set len
[
r llen $key
]
set len
[
r llen $key
]
for
{
set i 0
}
{
$i
< $len
}
{
incr i
}
{
for
{
set i 0
}
{
$i
< $len
}
{
incr i
}
{
...
@@ -87,33 +96,26 @@ start_server {
...
@@ -87,33 +96,26 @@ start_server {
}
}
}
}
test
{
LINDEX consistency test - ziplist
}
{
test
"LINDEX consistency test -
$type
"
{
populate_with_numbers myziplist 250
r del mylist
assert_encoding ziplist myziplist
for
{
set i 0
}
{
$i
< $num
}
{
incr i
}
{
r rpush mylist $i
}
}
assert_encoding $type mylist
test
{
LINDEX consistency test - regular list
}
{
populate_with_numbers mylist 500
assert_encoding list mylist
check_numbered_list_consistency mylist
check_numbered_list_consistency mylist
}
}
test
{
LINDEX random access - ziplist
}
{
test
"LINDEX random access -
$type
"
{
assert_encoding ziplist myziplist
assert_encoding $type mylist
check_random_access_consistency myziplist
}
test
{
LINDEX random access - regular list
}
{
assert_encoding list mylist
check_random_access_consistency mylist
check_random_access_consistency mylist
}
}
test
{
Check if
both list encodings are
still ok after a DEBUG RELOAD
}
{
test
"
Check if
list is
still ok after a DEBUG RELOAD
-
$type
"
{
r debug reload
r debug reload
assert_encoding ziplist myziplist
assert_encoding $type mylist
check_numbered_list_consistency myziplist
assert_encoding list mylist
check_numbered_list_consistency mylist
check_numbered_list_consistency mylist
check_random_access_consistency mylist
}
}
}
test
{
LLEN against non-list value error
}
{
test
{
LLEN against non-list value error
}
{
...
@@ -142,23 +144,10 @@ start_server {
...
@@ -142,23 +144,10 @@ start_server {
assert_error ERR*
{
r rpush mylist 0
}
assert_error ERR*
{
r rpush mylist 0
}
}
}
proc create_ziplist
{
key entries
}
{
foreach type
{
ziplist list
}
{
r del $key
test
"RPOPLPUSH base case -
$type
"
{
foreach entry $entries
{
r rpush $key $entry
}
assert_match *encoding:ziplist*
[
r debug object $key
]
}
proc create_regular_list
{
key entries
}
{
r del $key
r rpush $key
"aaaaaaaaaaaaaaaaa"
foreach entry $entries
{
r rpush $key $entry
}
assert_equal
"aaaaaaaaaaaaaaaaa"
[
r lpop $key
]
assert_match *encoding:list*
[
r debug object $key
]
}
test
{
RPOPLPUSH base case - ziplist
}
{
r del mylist1 mylist2
r del mylist1 mylist2
create_
ziplist
mylist1
{
a b c d
}
create_
$type
mylist1
{
a b c d
}
assert_equal d
[
r rpoplpush mylist1 mylist2
]
assert_equal d
[
r rpoplpush mylist1 mylist2
]
assert_equal c
[
r rpoplpush mylist1 mylist2
]
assert_equal c
[
r rpoplpush mylist1 mylist2
]
assert_equal
{
a b
}
[
r lrange mylist1 0 -1
]
assert_equal
{
a b
}
[
r lrange mylist1 0 -1
]
...
@@ -166,46 +155,23 @@ start_server {
...
@@ -166,46 +155,23 @@ start_server {
assert_encoding ziplist mylist2
assert_encoding ziplist mylist2
}
}
test
{
RPOPLPUSH base case - regular list
}
{
test
"RPOPLPUSH with the same list as src and dst -
$type
"
{
r del mylist1 mylist2
create_$type mylist
{
a b c
}
create_regular_list mylist1
{
a b c d
}
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
{
a b c
}
[
r lrange mylist 0 -1
]
assert_equal c
[
r rpoplpush mylist mylist
]
assert_equal c
[
r rpoplpush mylist mylist
]
assert_equal
{
c a b
}
[
r lrange mylist 0 -1
]
assert_equal
{
c a b
}
[
r lrange mylist 0 -1
]
}
}
test
{
RPOPLPUSH target list already exists, being a ziplist
}
{
foreach othertype
{
ziplist list
}
{
create_regular_list srclist
{
a b c d
}
test
"RPOPLPUSH with
$type
source and existing target
$othertype
"
{
create_ziplist dstlist
{
x
}
create_$type srclist
{
a b c d
}
create_$othertype dstlist
{
x
}
assert_equal d
[
r rpoplpush srclist dstlist
]
assert_equal d
[
r rpoplpush srclist dstlist
]
assert_equal c
[
r rpoplpush srclist dstlist
]
assert_equal c
[
r rpoplpush srclist dstlist
]
assert_equal
{
a b
}
[
r lrange srclist 0 -1
]
assert_equal
{
a b
}
[
r lrange srclist 0 -1
]
assert_equal
{
c d x
}
[
r lrange dstlist 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
}
{
...
@@ -236,20 +202,9 @@ start_server {
...
@@ -236,20 +202,9 @@ start_server {
assert_equal
{}
[
r rpoplpush srclist dstlist
]
assert_equal
{}
[
r rpoplpush srclist dstlist
]
}
{}
}
{}
test
{
Basic LPOP/RPOP - ziplist
}
{
foreach type
{
ziplist list
}
{
create_ziplist myziplist
{
0 1 2
}
test
"Basic LPOP/RPOP -
$type
"
{
assert_equal 0
[
r lpop myziplist
]
create_$type mylist
{
0 1 2
}
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 0
[
r lpop mylist
]
assert_equal 2
[
r rpop mylist
]
assert_equal 2
[
r rpop mylist
]
assert_equal 1
[
r lpop mylist
]
assert_equal 1
[
r lpop mylist
]
...
@@ -259,6 +214,7 @@ start_server {
...
@@ -259,6 +214,7 @@ start_server {
assert_equal
{}
[
r lpop mylist
]
assert_equal
{}
[
r lpop mylist
]
assert_equal
{}
[
r rpop mylist
]
assert_equal
{}
[
r rpop mylist
]
}
}
}
test
{
LPOP/RPOP against non list value
}
{
test
{
LPOP/RPOP against non list value
}
{
r set notalist foo
r set notalist foo
...
@@ -266,91 +222,50 @@ start_server {
...
@@ -266,91 +222,50 @@ start_server {
assert_error ERR*kind*
{
r rpop notalist
}
assert_error ERR*kind*
{
r rpop notalist
}
}
}
test
{
Mass RPOP/LPOP - ziplist
}
{
foreach
{
type num
}
{
ziplist 250 list 500
}
{
r del mylist
test
"Mass RPOP/LPOP -
$type
"
{
set sum1 0
for
{
set i 0
}
{
$i
< 250
}
{
incr i
}
{
r lpush mylist $i
incr sum1 $i
}
assert_encoding ziplist mylist
set sum2 0
for
{
set i 0
}
{
$i
< 125
}
{
incr i
}
{
incr sum2
[
r lpop mylist
]
incr sum2
[
r rpop mylist
]
}
assert_equal $sum1 $sum2
}
test
{
Mass RPOP/LPOP - regular list
}
{
r del mylist
r del mylist
set sum1 0
set sum1 0
for
{
set i 0
}
{
$i
<
500
}
{
incr i
}
{
for
{
set i 0
}
{
$i
<
$num
}
{
incr i
}
{
r lpush mylist $i
r lpush mylist $i
incr sum1 $i
incr sum1 $i
}
}
assert_encoding
list
mylist
assert_encoding
$type
mylist
set sum2 0
set sum2 0
for
{
set i 0
}
{
$i
<
250
}
{
incr i
}
{
for
{
set i 0
}
{
$i
<
[
expr $num/2
]
}
{
incr i
}
{
incr sum2
[
r lpop mylist
]
incr sum2
[
r lpop mylist
]
incr sum2
[
r rpop mylist
]
incr sum2
[
r rpop mylist
]
}
}
assert_equal $sum1 $sum2
assert_equal $sum1 $sum2
}
}
test
{
LRANGE basics - ziplist
}
{
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 basics - ziplist
}
{
foreach type
{
ziplist list
}
{
create_regular_list mylist
{
0 1 2 3 4 5 6 7 8 9
}
test
"LRANGE basics -
$type
"
{
create_$type 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
{
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
{
7 8 9
}
[
r lrange mylist -3 -1
]
assert_equal
{
4
}
[
r lrange mylist 4 4
]
assert_equal
{
4
}
[
r lrange mylist 4 4
]
}
}
test
{
LRANGE inverted indexes - ziplist
}
{
test
"LRANGE inverted indexes -
$type
"
{
create_ziplist mylist
{
0 1 2 3 4 5 6 7 8 9
}
create_$type 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
]
assert_equal
{}
[
r lrange mylist 6 2
]
}
}
test
{
LRANGE out of range indexes including the full list -
ziplist
}
{
test
"
LRANGE out of range indexes including the full list -
$type
"
{
create_
ziplist
mylist
{
1 2 3
}
create_
$type
mylist
{
1 2 3
}
assert_equal
{
1 2 3
}
[
r lrange mylist -1000 1000
]
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
}
{
assert_equal
{}
[
r lrange nosuchkey 0 1
]
assert_equal
{}
[
r lrange nosuchkey 0 1
]
}
}
test
{
LTRIM basics - ziplist
}
{
foreach type
{
ziplist list
}
{
r del mylist
test
"LTRIM basics -
$type
"
{
r lpush mylist
"aaa"
create_$type mylist
"foo"
assert_encoding ziplist 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 basics - regular list
}
{
r del mylist
r lpush mylist
"aaaaaaaaaaaaaaaaa"
assert_encoding list 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
...
@@ -358,30 +273,15 @@ start_server {
...
@@ -358,30 +273,15 @@ start_server {
r lrange mylist 0 -1
r lrange mylist 0 -1
}
{
99 98 97 96 95
}
}
{
99 98 97 96 95
}
test
{
LTRIM stress testing -
ziplist
}
{
test
"
LTRIM stress testing -
$type
"
{
set mylist
{}
set mylist
{}
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
}
{
create_ziplist mylist $mylist
create_$type 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
{
LTRIM stress testing - regular list
}
{
set mylist
{}
for
{
set i 0
}
{
$i
< 20
}
{
incr i
}
{
lappend mylist $i
}
for
{
set j 0
}
{
$j
< 100
}
{
incr j
}
{
create_regular_list mylist $mylist
# Trim at random
# Trim at random
set a
[
randomInt 20
]
set a
[
randomInt 20
]
set b
[
randomInt 20
]
set b
[
randomInt 20
]
...
@@ -390,27 +290,20 @@ start_server {
...
@@ -390,27 +290,20 @@ start_server {
}
}
}
}
test
{
LSET - ziplist
}
{
create_ziplist 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 - ziplist
}
{
assert_error ERR*range*
{
r lset mylist 10 foo
}
}
}
test
{
LSET - regular list
}
{
foreach type
{
ziplist list
}
{
create_regular_list mylist
{
99 98 97 96 95
}
test
"LSET -
$type
"
{
create_$type 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
assert_equal
{
99 foo 97 96 bar
}
[
r lrange mylist 0 -1
]
assert_equal
{
99 foo 97 96 bar
}
[
r lrange mylist 0 -1
]
}
}
test
{
LSET out of range index -
regular list
}
{
test
"
LSET out of range index -
$type
"
{
assert_error ERR*range*
{
r lset mylist 10 foo
}
assert_error ERR*range*
{
r lset mylist 10 foo
}
}
}
}
test
{
LSET against non existing key
}
{
test
{
LSET against non existing key
}
{
assert_error ERR*key*
{
r lset nosuchkey 10 foo
}
assert_error ERR*key*
{
r lset nosuchkey 10 foo
}
...
@@ -421,37 +314,35 @@ start_server {
...
@@ -421,37 +314,35 @@ start_server {
assert_error ERR*value*
{
r lset nolist 0 foo
}
assert_error ERR*value*
{
r lset nolist 0 foo
}
}
}
foreach type
{
ziplist regular_list
}
{
foreach type
{
ziplist list
}
{
set formatted_type
[
string map
{
"_"
" "
}
$type
]
test
"LREM remove all the occurrences -
$type
"
{
test
"LREM remove all the occurrences -
$formatted
_type"
{
create_$type mylist
{
foo bar foobar foobared zap bar test foo
}
create_$type mylist
{
foo bar foobar foobared zap bar test foo
}
assert_equal 2
[
r lrem mylist 0 bar
]
assert_equal 2
[
r lrem mylist 0 bar
]
assert_equal
{
foo foobar foobared zap test foo
}
[
r lrange mylist 0 -1
]
assert_equal
{
foo foobar foobared zap test foo
}
[
r lrange mylist 0 -1
]
}
}
test
"LREM remove the first occurrence -
$
formatted
_
type"
{
test
"LREM remove the first occurrence -
$type
"
{
assert_equal 1
[
r lrem mylist 1 foo
]
assert_equal 1
[
r lrem mylist 1 foo
]
assert_equal
{
foobar foobared zap test foo
}
[
r lrange mylist 0 -1
]
assert_equal
{
foobar foobared zap test foo
}
[
r lrange mylist 0 -1
]
}
}
test
"LREM remove non existing element -
$
formatted
_
type"
{
test
"LREM remove non existing element -
$type
"
{
assert_equal 0
[
r lrem mylist 1 nosuchelement
]
assert_equal 0
[
r lrem mylist 1 nosuchelement
]
assert_equal
{
foobar foobared zap test foo
}
[
r lrange mylist 0 -1
]
assert_equal
{
foobar foobared zap test foo
}
[
r lrange mylist 0 -1
]
}
}
test
"LREM starting from tail with negative count -
$
formatted
_
type"
{
test
"LREM starting from tail with negative count -
$type
"
{
create_$type mylist
{
foo bar foobar foobared zap bar test foo foo
}
create_$type mylist
{
foo bar foobar foobared zap bar test foo foo
}
assert_equal 1
[
r lrem mylist -1 bar
]
assert_equal 1
[
r lrem mylist -1 bar
]
assert_equal
{
foo bar foobar foobared zap test foo foo
}
[
r lrange mylist 0 -1
]
assert_equal
{
foo bar foobar foobared zap test foo foo
}
[
r lrange mylist 0 -1
]
}
}
test
"LREM starting from tail with negative count (2) -
$
formatted
_
type"
{
test
"LREM starting from tail with negative count (2) -
$type
"
{
assert_equal 2
[
r lrem mylist -2 foo
]
assert_equal 2
[
r lrem mylist -2 foo
]
assert_equal
{
foo bar foobar foobared zap test
}
[
r lrange mylist 0 -1
]
assert_equal
{
foo bar foobar foobared zap test
}
[
r lrange mylist 0 -1
]
}
}
test
"LREM deleting objects that may be int encoded -
$
formatted
_
type"
{
test
"LREM deleting objects that may be int encoded -
$type
"
{
create_$type myotherlist
{
1 2 3
}
create_$type myotherlist
{
1 2 3
}
assert_equal 1
[
r lrem myotherlist 1 2
]
assert_equal 1
[
r lrem myotherlist 1 2
]
assert_equal 2
[
r llen myotherlist
]
assert_equal 2
[
r llen myotherlist
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment