Skip to content

Commit

Permalink
Add 2 test cases for XDEL and XGROUP CREATE command (redis#11137)
Browse files Browse the repository at this point in the history
This PR includes 2 missed test cases of XDEL and XGROUP CREATE command

1. one test case: XDEL delete multiply id once
2. 3 test cases:  XGROUP CREATE has ENTRIESREAD parameter,
   which equal 0 (special positive number), 3 and negative value.


Co-authored-by: Ubuntu <lucas.guang.yang1@huawei.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
Co-authored-by: Binbin <binloveplay1314@qq.com>
  • Loading branch information
4 people committed Aug 21, 2022
1 parent 3a16ad3 commit c3a0253
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/unit/type/stream-cgroups.tcl
Expand Up @@ -9,6 +9,29 @@ start_server {
set err
} {BUSYGROUP*}

test {XGROUP CREATE: with ENTRIESREAD parameter} {
r DEL mystream
r XADD mystream 1-1 a 1
r XADD mystream 1-2 b 2
r XADD mystream 1-3 c 3
r XADD mystream 1-4 d 4
assert_error "*value for ENTRIESREAD must be positive or -1*" {r XGROUP CREATE mystream mygroup $ ENTRIESREAD -3}

r XGROUP CREATE mystream mygroup1 $ ENTRIESREAD 0
r XGROUP CREATE mystream mygroup2 $ ENTRIESREAD 3

set reply [r xinfo groups mystream]
foreach group_info $reply {
set group_name [dict get $group_info name]
set entries_read [dict get $group_info entries-read]
if {$group_name == "mygroup1"} {
assert_equal $entries_read 0
} else {
assert_equal $entries_read 3
}
}
}

test {XGROUP CREATE: automatic stream creation fails without MKSTREAM} {
r DEL mystream
catch {r XGROUP CREATE mystream mygroup $} err
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/type/stream.tcl
Expand Up @@ -469,6 +469,20 @@ start_server {
assert {[lindex $result 1 1 1] eq {value2}}
}

test {XDEL multiply id test} {
r del somestream
r xadd somestream 1-1 a 1
r xadd somestream 1-2 b 2
r xadd somestream 1-3 c 3
r xadd somestream 1-4 d 4
r xadd somestream 1-5 e 5
assert {[r xlen somestream] == 5}
assert {[r xdel somestream 1-1 1-4 1-5 2-1] == 3}
assert {[r xlen somestream] == 2}
set result [r xrange somestream - +]
assert {[dict get [lindex $result 0 1] b] eq {2}}
assert {[dict get [lindex $result 1 1] c] eq {3}}
}
# Here the idea is to check the consistency of the stream data structure
# as we remove all the elements down to zero elements.
test {XDEL fuzz test} {
Expand Down

0 comments on commit c3a0253

Please sign in to comment.