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 {
assert_equal 0
[
r llen mylist2
]
}
proc populate_with_numbers
{
key num
}
{
for
{
set i 0
}
{
$i
< $num
}
{
incr i
}
{
r rpush $key $i
proc create_ziplist
{
key entries
}
{
r del $key
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
}
{
set len
[
r llen $key
]
for
{
set i 0
}
{
$i
< $len
}
{
incr i
}
{
...
...
@@ -87,33 +96,26 @@ start_server {
}
}
test
{
LINDEX consistency test - ziplist
}
{
populate_with_numbers myziplist 250
assert_encoding ziplist myziplist
test
"LINDEX consistency test -
$type
"
{
r del mylist
for
{
set i 0
}
{
$i
< $num
}
{
incr i
}
{
r rpush mylist $i
}
test
{
LINDEX consistency test - regular list
}
{
populate_with_numbers mylist 500
assert_encoding list mylist
assert_encoding $type 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
test
"LINDEX random access -
$type
"
{
assert_encoding $type 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
assert_encoding ziplist myziplist
check_numbered_list_consistency myziplist
assert_encoding list mylist
assert_encoding $type mylist
check_numbered_list_consistency mylist
check_random_access_consistency mylist
}
}
test
{
LLEN against non-list value error
}
{
...
...
@@ -142,23 +144,10 @@ start_server {
assert_error ERR*
{
r rpush mylist 0
}
}
proc create_ziplist
{
key entries
}
{
r del $key
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
}
{
foreach type
{
ziplist list
}
{
test
"RPOPLPUSH base case -
$type
"
{
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 c
[
r rpoplpush mylist1 mylist2
]
assert_equal
{
a b
}
[
r lrange mylist1 0 -1
]
...
...
@@ -166,46 +155,23 @@ start_server {
assert_encoding ziplist mylist2
}
test
{
RPOPLPUSH base case - regular list
}
{
r del mylist1 mylist2
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
}
test
"RPOPLPUSH with the same list as src and dst -
$type
"
{
create_$type 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
}
foreach othertype
{
ziplist list
}
{
test
"RPOPLPUSH with
$type
source and existing target
$othertype
"
{
create_$type srclist
{
a b c d
}
create_$othertype 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
}
{
...
...
@@ -236,20 +202,9 @@ start_server {
assert_equal
{}
[
r rpoplpush srclist dstlist
]
}
{}
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
}
foreach type
{
ziplist list
}
{
test
"Basic LPOP/RPOP -
$type
"
{
create_$type mylist
{
0 1 2
}
assert_equal 0
[
r lpop mylist
]
assert_equal 2
[
r rpop mylist
]
assert_equal 1
[
r lpop mylist
]
...
...
@@ -259,6 +214,7 @@ start_server {
assert_equal
{}
[
r lpop mylist
]
assert_equal
{}
[
r rpop mylist
]
}
}
test
{
LPOP/RPOP against non list value
}
{
r set notalist foo
...
...
@@ -266,91 +222,50 @@ start_server {
assert_error ERR*kind*
{
r rpop notalist
}
}
test
{
Mass RPOP/LPOP - ziplist
}
{
r del mylist
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
}
{
foreach
{
type num
}
{
ziplist 250 list 500
}
{
test
"Mass RPOP/LPOP -
$type
"
{
r del mylist
set sum1 0
for
{
set i 0
}
{
$i
<
500
}
{
incr i
}
{
for
{
set i 0
}
{
$i
<
$num
}
{
incr i
}
{
r lpush mylist $i
incr sum1 $i
}
assert_encoding
list
mylist
assert_encoding
$type
mylist
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 rpop mylist
]
}
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
}
{
create_regular_list mylist
{
0 1 2 3 4 5 6 7 8 9
}
foreach type
{
ziplist list
}
{
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
{
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
}
test
"LRANGE inverted indexes -
$type
"
{
create_$type 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
}
test
"
LRANGE out of range indexes including the full list -
$type
"
{
create_
$type
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
}
{
assert_equal
{}
[
r lrange nosuchkey 0 1
]
}
test
{
LTRIM basics - ziplist
}
{
r del mylist
r lpush mylist
"aaa"
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
foreach type
{
ziplist list
}
{
test
"LTRIM basics -
$type
"
{
create_$type mylist
"foo"
for
{
set i 0
}
{
$i
< 100
}
{
incr i
}
{
r lpush mylist $i
r ltrim mylist 0 4
...
...
@@ -358,30 +273,15 @@ start_server {
r lrange mylist 0 -1
}
{
99 98 97 96 95
}
test
{
LTRIM stress testing -
ziplist
}
{
test
"
LTRIM stress testing -
$type
"
{
set mylist
{}
for
{
set i 0
}
{
$i
< 20
}
{
incr i
}
{
lappend mylist $i
}
for
{
set j 0
}
{
$j
< 100
}
{
incr j
}
{
create_ziplist 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
]
}
}
create_$type mylist $mylist
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
set a
[
randomInt 20
]
set b
[
randomInt 20
]
...
...
@@ -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
}
{
create_regular_list mylist
{
99 98 97 96 95
}
foreach type
{
ziplist list
}
{
test
"LSET -
$type
"
{
create_$type 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
}
{
test
"
LSET out of range index -
$type
"
{
assert_error ERR*range*
{
r lset mylist 10 foo
}
}
}
test
{
LSET against non existing key
}
{
assert_error ERR*key*
{
r lset nosuchkey 10 foo
}
...
...
@@ -421,37 +314,35 @@ start_server {
assert_error ERR*value*
{
r lset nolist 0 foo
}
}
foreach type
{
ziplist regular_list
}
{
set formatted_type
[
string map
{
"_"
" "
}
$type
]
test
"LREM remove all the occurrences -
$formatted
_type"
{
foreach type
{
ziplist list
}
{
test
"LREM remove all the occurrences -
$type
"
{
create_$type mylist
{
foo bar foobar foobared zap bar test foo
}
assert_equal 2
[
r lrem mylist 0 bar
]
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
{
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
{
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
}
assert_equal 1
[
r lrem mylist -1 bar
]
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
{
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
}
assert_equal 1
[
r lrem myotherlist 1 2
]
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