Skip to content

Commit

Permalink
fix: the unit test of type/set (#1617)
Browse files Browse the repository at this point in the history
* test: optimize the return results of srandmember to avoid approximate results

* fix: use last_seed for random engine
  • Loading branch information
machinly authored Jun 18, 2023
1 parent 59b1193 commit 9d4df2e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/storage/src/redis_sets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ rocksdb::Status RedisSets::SRandmember(const Slice& key, int32_t count, std::vec
}

members->clear();
int32_t last_seed = time(nullptr);
int64_t last_seed = pstd::NowMicros();
std::default_random_engine engine;

std::string meta_value;
Expand Down
14 changes: 0 additions & 14 deletions tests/support/test.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,3 @@ proc test {name code {okpattern undefined}} {
}
}

proc uniqkey { } {
set key [ expr { [ expr { 1 << 31 } ] + [ clock clicks ] } ]
set key [ string range $key end-8 end-3 ]
set key [ clock seconds ]$key
return $key
}

proc sleep { ms } {
set uniq [ uniqkey ]
set ::__sleep__tmp__$uniq 0
after $ms set ::__sleep__tmp__$uniq 1
vwait ::__sleep__tmp__$uniq
unset ::__sleep__tmp__$uniq
}
2 changes: 1 addition & 1 deletion tests/test_helper.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set ::all_tests {
# unit/type/list
unit/type/list-2
unit/type/list-3
# unit/type/set
unit/type/set
unit/type/zset
# unit/type/hash
# unit/sort
Expand Down
9 changes: 3 additions & 6 deletions tests/unit/type/set.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ start_server {
create_set myset $contents
unset -nocomplain myset
array set myset {}
for {set i 0} {$i < 500} {incr i} {
sleep 10
for {set i 0} {$i < 100} {incr i} {
set myset([r srandmember myset]) 1
}
assert_equal $contents [lsort [array names myset]]
Expand Down Expand Up @@ -359,15 +358,14 @@ start_server {
set iterations 1000
while {$iterations != 0} {
incr iterations -1
set res [r srandmember myset -20]
set res [r srandmember myset -10]
foreach ele $res {
set auxset($ele) 1
}
if {[lsort [array names myset]] eq
[lsort [array names auxset]]} {
break;
}
sleep 15
}
assert {$iterations != 0}

Expand Down Expand Up @@ -404,15 +402,14 @@ start_server {
set iterations 1000
while {$iterations != 0} {
incr iterations -1
set res [r srandmember myset -20]
set res [r srandmember myset -10]
foreach ele $res {
set auxset($ele) 1
}
if {[lsort [array names myset]] eq
[lsort [array names auxset]]} {
break;
}
sleep 15
}
assert {$iterations != 0}
}
Expand Down

0 comments on commit 9d4df2e

Please sign in to comment.