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
eb1230c9
Commit
eb1230c9
authored
Sep 18, 2017
by
antirez
Browse files
Streams: XRANGE fuzz testing.
parent
fa707ca1
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/unit/type/stream.tcl
View file @
eb1230c9
# return value is like strcmp
()
and similar.
# return value is like strcmp
()
and similar.
proc streamCompareID
{
a b
}
{
proc streamCompareID
{
a b
}
{
if
{
$a
==
$b
}
{
return 0
}
if
{
$a
eq
$b
}
{
return 0
}
lassign
[
split $a .
]
a_ms a_seq
lassign
[
split $a .
]
a_ms a_seq
lassign
[
split $b .
]
b_ms b_seq
lassign
[
split $b .
]
b_ms b_seq
if
{
$a
_ms > $b_ms
}
{
return 1
}
if
{
$a
_ms > $b_ms
}
{
return 1
}
...
@@ -19,6 +19,36 @@ proc streamNextID {id} {
...
@@ -19,6 +19,36 @@ proc streamNextID {id} {
join
[
list $ms $seq
]
.
join
[
list $ms $seq
]
.
}
}
# Generate a random stream entry ID with the ms part between min and max
# and a low sequence number
(
0 - 999 range
)
, in order to stress test
# XRANGE against a Tcl implementation implementing the same concept
# with Tcl-only code in a linear array.
proc streamRandomID
{
min_id max_id
}
{
lassign
[
split $min_id .
]
min_ms min_seq
lassign
[
split $max_id .
]
max_ms max_seq
set delta
[
expr
{
$max
_ms-$min_ms+1
}]
set ms
[
expr
{
$min
_ms+
[
randomInt $delta
]}]
set seq
[
randomInt 1000
]
return $ms.$seq
}
# Tcl-side implementation of XRANGE to perform fuzz testing in the Redis
# XRANGE implementation.
proc streamSimulateXRANGE
{
items start end
}
{
set res
{}
foreach i $items
{
set this_id
[
lindex $i 0
]
if
{[
streamCompareID $this_id $start
]
>= 0
}
{
if
{[
streamCompareID $this_id $end
]
<= 0
}
{
lappend res $i
}
}
}
return $res
}
set content
{}
;
# Will be populated with Tcl side copy of the stream content.
start_server
{
start_server
{
tags
{
"stream"
}
tags
{
"stream"
}
}
{
}
{
...
@@ -82,4 +112,25 @@ start_server {
...
@@ -82,4 +112,25 @@ start_server {
}
}
assert
{
$j
== 10000
}
assert
{
$j
== 10000
}
}
}
test
{
XRANGE fuzzing
}
{
# puts $items
set low_id
[
lindex $items 0 0
]
set high_id
[
lindex $items end 0
]
for
{
set j 0
}
{
$j
< 100
}
{
incr j
}
{
set start
[
streamRandomID $low_id $high_id
]
set end
[
streamRandomID $low_id $high_id
]
set range
[
r xrange mystream $start $end
]
set tcl_range
[
streamSimulateXRANGE $items $start $end
]
if
{
$range
ne $tcl_range
}
{
puts
"*** WARNING *** - XRANGE fuzzing mismatch:
$start
-
$end
"
puts
"---"
puts
"XRANGE: '
$range
'"
puts
"---"
puts
"TCL: '
$tcl
_range'"
puts
"---"
fail
"XRANGE fuzzing failed, check logs for details"
}
}
}
}
}
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