From fa707ca15477c5d5871668a7b2ca2040b992df48 Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 15 Sep 2017 16:56:18 +0200 Subject: [PATCH] Streams: more advanced XADD and XRANGE tests. --- tests/unit/type/stream.tcl | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/unit/type/stream.tcl b/tests/unit/type/stream.tcl index a668ddf4..35de5c1f 100644 --- a/tests/unit/type/stream.tcl +++ b/tests/unit/type/stream.tcl @@ -10,6 +10,15 @@ proc streamCompareID {a b} { if {$a_seq < $b_seq} {return -1} } +# return the ID immediately greater than the specified one. +# Note that this function does not care to handle 'seq' overflow +# since it's a 64 bit value. +proc streamNextID {id} { + lassign [split $id .] ms seq + incr seq + join [list $ms $seq] . +} + start_server { tags {"stream"} } { @@ -39,4 +48,38 @@ start_server { assert {[streamCompareID $id1 $id2] == -1} assert {[streamCompareID $id2 $id3] == -1} } + + test {XADD mass insertion and XLEN} { + r DEL mystream + r multi + for {set j 0} {$j < 10000} {incr j} { + r XADD mystream * item $j + } + r exec + + set items [r XRANGE mystream - +] + for {set j 0} {$j < 10000} {incr j} { + assert {[lindex $items $j 1] eq [list item $j]} + } + assert {[r xlen mystream] == $j} + } + + test {XRANGE COUNT works as expected} { + assert {[llength [r xrange mystream - + COUNT 10]] == 10} + } + + test {XRANGE can be used to iterate the whole stream} { + set last_id "-" + set j 0 + while 1 { + set elements [r xrange mystream $last_id + COUNT 100] + if {[llength $elements] == 0} break + foreach e $elements { + assert {[lindex $e 1] eq [list item $j]} + incr j; + } + set last_id [streamNextID [lindex $elements end 0]] + } + assert {$j == 10000} + } }