Commit 280b2dc1 authored by antirez's avatar antirez
Browse files

Improved regression test for #4906.

Removing the fix about 50% of the times the test will not be able to
pass cleanly. It's very hard to write a test that will always fail, or
actually, it is possible but then it's likely that it will consistently
pass if we change some random bit, so better to use randomization here.
parent 260b32ed
...@@ -238,39 +238,47 @@ start_server {tags {"scan"}} { ...@@ -238,39 +238,47 @@ start_server {tags {"scan"}} {
} }
test "SCAN regression test for issue #4906" { test "SCAN regression test for issue #4906" {
r del set for {set k 0} {$k < 100} {incr k} {
set toremove {} r del set
array set found {} r sadd set x; # Make sure it's not intset encoded
for {set j 0} {$j < 500} {incr j} { set toremove {}
r sadd set $j unset -nocomplain found
if {$j >= 100} { array set found {}
lappend toremove $j
# Populate the set
set numele [expr {100+[randomInt 1000]}]
for {set j 0} {$j < $numele} {incr j} {
r sadd set $j
if {$j >= 100} {
lappend toremove $j
}
} }
}
# Start scanning # Start scanning
set cursor 0 set cursor 0
set iteration 0 set iteration 0
while {!($cursor == 0 && $iteration != 0)} { set del_iteration [randomInt 10]
lassign [r sscan set $cursor] cursor items while {!($cursor == 0 && $iteration != 0)} {
lassign [r sscan set $cursor] cursor items
# Mark found items. We expect to find from 0 to 99 at the end
# since those elements will never be removed during the scanning. # Mark found items. We expect to find from 0 to 99 at the end
foreach i $items { # since those elements will never be removed during the scanning.
set found($i) 1 foreach i $items {
} set found($i) 1
incr iteration }
# At some point remove most of the items to trigger the incr iteration
# rehashing to a smaller hash table. # At some point remove most of the items to trigger the
if {$iteration == 1} { # rehashing to a smaller hash table.
r srem set {*}$toremove if {$iteration == $del_iteration} {
r srem set {*}$toremove
}
} }
}
# Verify that SSCAN reported everything from 0 to 99 # Verify that SSCAN reported everything from 0 to 99
for {set j 0} {$j < 100} {incr j} { for {set j 0} {$j < 100} {incr j} {
if {![info exists found($j)]} { if {![info exists found($j)]} {
fail "SSCAN element missing $j" fail "SSCAN element missing $j"
}
} }
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment