}
close $fd
} e]} {
- puts "Can't PING server at $host:$port... $e"
+ puts -nonewline "."
+ } else {
+ puts -nonewline "ok"
}
return $retval
}
if {$::valgrind} {
exec valgrind src/redis-server $config_file > $stdout 2> $stderr &
- after 2000
} else {
exec src/redis-server $config_file > $stdout 2> $stderr &
- after 500
}
# check that the server actually started
- if {$code ne "undefined" && ![ping_server $::host $::port]} {
+ # ugly but tries to be as fast as possible...
+ set retrynum 20
+ set serverisup 0
+
+ puts -nonewline "=== ($tags) Starting server ${::host}:${::port} "
+ after 10
+ if {$code ne "undefined"} {
+ while {[incr retrynum -1]} {
+ catch {
+ if {[ping_server $::host $::port]} {
+ set serverisup 1
+ }
+ }
+ if {$serverisup} break
+ after 50
+ }
+ } else {
+ set serverisup 1
+ }
+ puts {}
+
+ if {!$serverisup} {
error_and_quit $config_file [exec cat $stderr]
}
}
r sadd set5 0
- # it is possible that a hashtable encoded only contains integers,
- # because it is converted from an intset to a hashtable when a
- # non-integer element is added and then removed.
+ # To make sure the sets are encoded as the type we are testing -- also
+ # when the VM is enabled and the values may be swapped in and out
+ # while the tests are running -- an extra element is added to every
+ # set that determines its encoding.
+ set large 200
if {$type eq "hashtable"} {
- for {set i 1} {$i <= 5} {incr i} {
- r sadd [format "set%d" $i] foo
- r srem [format "set%d" $i] foo
- }
+ set large foo
+ }
+
+ for {set i 1} {$i <= 5} {incr i} {
+ r sadd [format "set%d" $i] $large
}
test "Generated sets must be encoded as $type" {
}
test "SINTER with two sets - $type" {
- assert_equal {195 196 197 198 199} [lsort [r sinter set1 set2]]
+ assert_equal [list 195 196 197 198 199 $large] [lsort [r sinter set1 set2]]
}
test "SINTERSTORE with two sets - $type" {
r sinterstore setres set1 set2
- assert_encoding intset setres
- assert_equal {195 196 197 198 199} [lsort [r smembers setres]]
+ assert_encoding $type setres
+ assert_equal [list 195 196 197 198 199 $large] [lsort [r smembers setres]]
}
test "SINTERSTORE with two sets, after a DEBUG RELOAD - $type" {
r debug reload
r sinterstore setres set1 set2
- assert_encoding intset setres
- assert_equal {195 196 197 198 199} [lsort [r smembers setres]]
+ assert_encoding $type setres
+ assert_equal [list 195 196 197 198 199 $large] [lsort [r smembers setres]]
}
test "SUNION with two sets - $type" {
test "SUNIONSTORE with two sets - $type" {
r sunionstore setres set1 set2
- assert_encoding intset setres
+ assert_encoding $type setres
set expected [lsort -uniq "[r smembers set1] [r smembers set2]"]
assert_equal $expected [lsort [r smembers setres]]
}
test "SINTER against three sets - $type" {
- assert_equal {195 199} [lsort [r sinter set1 set2 set3]]
+ assert_equal [list 195 199 $large] [lsort [r sinter set1 set2 set3]]
}
test "SINTERSTORE with three sets - $type" {
r sinterstore setres set1 set2 set3
- assert_equal {195 199} [r smembers setres]
+ assert_equal [list 195 199 $large] [lsort [r smembers setres]]
}
test "SUNION with non existing keys - $type" {
test "SDIFFSTORE with three sets - $type" {
r sdiffstore setres set1 set4 set5
- assert_encoding intset setres
+ # The type is determined by type of the first key to diff against.
+ # See the implementation for more information.
+ assert_encoding $type setres
assert_equal {1 2 3 4} [lsort [r smembers setres]]
}
}