Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
08b59207
Commit
08b59207
authored
Jun 14, 2010
by
Pieter Noordhuis
Browse files
change ltrim tests to cover all min/max cases and add stronger stresser
parent
bb039e85
Changes
2
Show whitespace changes
Inline
Side-by-side
tests/support/test.tcl
View file @
08b59207
...
...
@@ -26,6 +26,8 @@ proc assert_error {pattern code} {
}
proc assert_encoding
{
enc key
}
{
# swapped out value doesn't have encoding, so swap in first
r debug swapin $key
assert_match
"* encoding:
$enc
*"
[
r debug object $key
]
}
...
...
tests/unit/type/list.tcl
View file @
08b59207
...
...
@@ -347,32 +347,61 @@ start_server {
}
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
}
proc trim_list
{
type min max
}
{
r del mylist
create_$type mylist
{
1 2 3 4 5
}
r ltrim mylist $min $max
r lrange mylist 0 -1
}
{
99 98 97 96 95
}
}
test
"LTRIM basics -
$type
"
{
assert_equal
{
1
}
[
trim_list $type 0 0
]
assert_equal
{
1 2
}
[
trim_list $type 0 1
]
assert_equal
{
1 2 3
}
[
trim_list $type 0 2
]
assert_equal
{
2 3
}
[
trim_list $type 1 2
]
assert_equal
{
2 3 4 5
}
[
trim_list $type 1 -1
]
assert_equal
{
2 3 4
}
[
trim_list $type 1 -2
]
assert_equal
{
4 5
}
[
trim_list $type -2 -1
]
assert_equal
{
5
}
[
trim_list $type -1 -1
]
assert_equal
{
1 2 3 4 5
}
[
trim_list $type -5 -1
]
assert_equal
{
1 2 3 4 5
}
[
trim_list $type -10 10
]
assert_equal
{
1 2 3 4 5
}
[
trim_list $type 0 5
]
assert_equal
{
1 2 3 4 5
}
[
trim_list $type 0 10
]
}
tags
{
"slow"
}
{
test
"LTRIM stress testing -
$type
"
{
set mylist
{}
for
{
set i 0
}
{
$i
< 20
}
{
incr i
}
{
lappend mylist $i
set startlen 32
r del mylist
for
{
set i 0
}
{
$i
< $startlen
}
{
incr i
}
{
set str
[
randomInt 9223372036854775807
]
r rpush mylist $str
lappend mylist $str
}
# do a push/pop of a large value to convert to a real list
if
{
$type
eq
"list"
}
{
r rpush mylist
"aaaaaaaaaaaaaaaaa"
r rpop mylist
assert_encoding list mylist
}
for
{
set j 0
}
{
$j
< 100
}
{
incr j
}
{
create_$type mylist $mylist
for
{
set i 0
}
{
$i
< 1000
}
{
incr i
}
{
set min
[
expr
{
int
(
rand
()
*$startlen
)}]
set max
[
expr
{
$min
+int
(
rand
()
*$startlen
)}]
set mylist
[
lrange $mylist $min $max
]
r ltrim mylist $min $max
assert_equal $mylist
[
r lrange mylist 0 -1
]
# 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
]
for
{
set j
[
r llen mylist
]}
{
$j
< $startlen
}
{
incr j
}
{
set str
[
randomInt 9223372036854775807
]
r rpush mylist $str
lappend mylist $str
}
}
}
}
}
foreach type
{
ziplist list
}
{
...
...
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