diff --git a/tests/unit/scan.tcl b/tests/unit/scan.tcl index a02f3a58..a8cc8116 100644 --- a/tests/unit/scan.tcl +++ b/tests/unit/scan.tcl @@ -238,39 +238,47 @@ start_server {tags {"scan"}} { } test "SCAN regression test for issue #4906" { - r del set - set toremove {} - array set found {} - for {set j 0} {$j < 500} {incr j} { - r sadd set $j - if {$j >= 100} { - lappend toremove $j - } - } + for {set k 0} {$k < 100} {incr k} { + r del set + r sadd set x; # Make sure it's not intset encoded + set toremove {} + unset -nocomplain found + array set found {} - # Start scanning - set cursor 0 - set iteration 0 - 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. - foreach i $items { - set found($i) 1 + # 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 + } } - incr iteration - # At some point remove most of the items to trigger the - # rehashing to a smaller hash table. - if {$iteration == 1} { - r srem set {*}$toremove - } - } - # Verify that SSCAN reported everything from 0 to 99 - for {set j 0} {$j < 100} {incr j} { - if {![info exists found($j)]} { - fail "SSCAN element missing $j" + # Start scanning + set cursor 0 + set iteration 0 + set del_iteration [randomInt 10] + 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. + foreach i $items { + set found($i) 1 + } + incr iteration + # At some point remove most of the items to trigger the + # rehashing to a smaller hash table. + if {$iteration == $del_iteration} { + r srem set {*}$toremove + } + } + + # Verify that SSCAN reported everything from 0 to 99 + for {set j 0} {$j < 100} {incr j} { + if {![info exists found($j)]} { + fail "SSCAN element missing $j" + } } } }