mirror of
http://github.com/valkey-io/valkey
synced 2024-11-22 09:17:20 +00:00
Streams: basic XADD tests.
This commit is contained in:
parent
26d4f8e3ec
commit
7a41b402c1
@ -26,6 +26,7 @@ set ::all_tests {
|
||||
unit/type/set
|
||||
unit/type/zset
|
||||
unit/type/hash
|
||||
unit/type/stream
|
||||
unit/sort
|
||||
unit/expire
|
||||
unit/other
|
||||
|
42
tests/unit/type/stream.tcl
Normal file
42
tests/unit/type/stream.tcl
Normal file
@ -0,0 +1,42 @@
|
||||
# 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}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user