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
7a41b402
Commit
7a41b402
authored
Sep 15, 2017
by
antirez
Browse files
Streams: basic XADD tests.
parent
26d4f8e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/test_helper.tcl
View file @
7a41b402
...
@@ -26,6 +26,7 @@ set ::all_tests {
...
@@ -26,6 +26,7 @@ set ::all_tests {
unit/type/set
unit/type/set
unit/type/zset
unit/type/zset
unit/type/hash
unit/type/hash
unit/type/stream
unit/sort
unit/sort
unit/expire
unit/expire
unit/other
unit/other
...
...
tests/unit/type/stream.tcl
0 → 100644
View file @
7a41b402
# return value is like strcmp
()
and similar.
proc streamCompareID
{
a b
}
{
if
{
$a
== $b
}
{
return 0
}
lassign
[
split $a .
]
a_ms a_seq
lassign
[
split $b .
]
b_ms b_seq
if
{
$a
_ms > $b_ms
}
{
return 1
}
if
{
$a
_ms < $b_ms
}
{
return -1
}
# Same ms case, compare seq.
if
{
$a
_seq > $b_seq
}
{
return 1
}
if
{
$a
_seq < $b_seq
}
{
return -1
}
}
start_server
{
tags
{
"stream"
}
}
{
test
{
XADD can add entries into a stream that XRANGE can fetch
}
{
r XADD mystream * item 1 value a
r XADD mystream * item 2 value b
assert_equal 2
[
r XLEN mystream
]
set items
[
r XRANGE mystream - +
]
assert_equal
[
lindex $items 0 1
]
{
item 1 value a
}
assert_equal
[
lindex $items 1 1
]
{
item 2 value b
}
}
test
{
XADD IDs are incremental
}
{
set id1
[
r XADD mystream * item 1 value a
]
set id2
[
r XADD mystream * item 2 value b
]
set id3
[
r XADD mystream * item 3 value c
]
assert
{[
streamCompareID $id1 $id2
]
== -1
}
assert
{[
streamCompareID $id2 $id3
]
== -1
}
}
test
{
XADD IDs are incremental when ms is the same as well
}
{
r multi
r XADD mystream * item 1 value a
r XADD mystream * item 2 value b
r XADD mystream * item 3 value c
lassign
[
r exec
]
id1 id2 id3
assert
{[
streamCompareID $id1 $id2
]
== -1
}
assert
{[
streamCompareID $id2 $id3
]
== -1
}
}
}
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