]> git.saurik.com Git - redis.git/blobdiff - test-redis.tcl
SORT support for sorted sets
[redis.git] / test-redis.tcl
index a4c3c618a2d72f99527b24af4fb3b8f91bf36f38..039941d3add28fe46fda688a07859056ea2a22e6 100644 (file)
@@ -1,4 +1,7 @@
-# TODO # test pipelining
+# test-redis.tcl
+# Redis test suite. Copyright (C) 2009 Salvatore Sanfilippo antirez@gmail.com
+# This softare is released under the BSD License. See the COPYING file for
+# more information.
 
 set tcl_precision 17
 source redis.tcl
@@ -235,6 +238,19 @@ proc main {server port} {
         format $ok
     } {2000}
 
+    test {Check if the list is still ok after a DEBUG RELOAD} {
+        $r debug reload
+        set ok 0
+        for {set i 0} {$i < 1000} {incr i} {
+            set rint [expr int(rand()*1000)]
+            if {[$r lindex mylist $rint] eq $rint} {incr ok}
+            if {[$r lindex mylist [expr (-$rint)-1]] eq [expr 999-$rint]} {
+                incr ok
+            }
+        }
+        format $ok
+    } {2000}
+
     test {LLEN against non-list value error} {
         $r del mylist
         $r set mylist foobar
@@ -551,6 +567,12 @@ proc main {server port} {
         lsort [$r smembers setres]
     } {995 996 997 998 999}
 
+    test {SINTERSTORE with two sets, after a DEBUG RELOAD} {
+        $r debug reload
+        $r sinterstore setres set1 set2
+        lsort [$r smembers setres]
+    } {995 996 997 998 999}
+
     test {SUNIONSTORE with two sets} {
         $r sunionstore setres set1 set2
         lsort [$r smembers setres]
@@ -906,6 +928,25 @@ proc main {server port} {
         set _ $err
     } {}
 
+    test {ZSCORE after a DEBUG RELOAD} {
+        set aux {}
+        set err {}
+        $r del zscoretest
+        for {set i 0} {$i < 1000} {incr i} {
+            set score [expr rand()]
+            lappend aux $score
+            $r zadd zscoretest $score $i
+        }
+        $r debug reload
+        for {set i 0} {$i < 1000} {incr i} {
+            if {[$r zscore zscoretest $i] != [lindex $aux $i]} {
+                set err "Expected score was [lindex $aux $i] but got [$r zscore zscoretest $i] for element $i"
+                break
+            }
+        }
+        set _ $err
+    } {}
+
     test {ZRANGE and ZREVRANGE} {
         list [$r zrange ztmp 0 -1] [$r zrevrange ztmp 0 -1]
     } {{y x z} {z x y}}
@@ -973,6 +1014,66 @@ proc main {server port} {
         list $v1 $v2 [$r zscore zset foo] [$r zscore zset bar]
     } {{bar foo} {foo bar} -2 6}
 
+    test {ZRANGEBYSCORE basics} {
+        $r del zset
+        $r zadd zset 1 a
+        $r zadd zset 2 b
+        $r zadd zset 3 c
+        $r zadd zset 4 d
+        $r zadd zset 5 e
+        $r zrangebyscore zset 2 4
+    } {b c d}
+
+    test {ZRANGEBYSCORE fuzzy test, 100 ranges in 1000 elements sorted set} {
+        set err {}
+        $r del zset
+        for {set i 0} {$i < 1000} {incr i} {
+            $r zadd zset [expr rand()] $i
+        }
+        for {set i 0} {$i < 100} {incr i} {
+            set min [expr rand()]
+            set max [expr rand()]
+            if {$min > $max} {
+                set aux $min
+                set min $max
+                set max $aux
+            }
+            set low [$r zrangebyscore zset -inf $min]
+            set ok [$r zrangebyscore zset $min $max]
+            set high [$r zrangebyscore zset $max +inf]
+            foreach x $low {
+                set score [$r zscore zset $x]
+                if {$score > $min} {
+                    append err "Error, score for $x is $score > $min\n"
+                }
+            }
+            foreach x $ok {
+                set score [$r zscore zset $x]
+                if {$score < $min || $score > $max} {
+                    append err "Error, score for $x is $score outside $min-$max range\n"
+                }
+            }
+            foreach x $high {
+                set score [$r zscore zset $x]
+                if {$score < $max} {
+                    append err "Error, score for $x is $score < $max\n"
+                }
+            }
+        }
+        set _ $err
+    } {}
+
+    test {Sorted sets +inf and -inf handling} {
+        $r del zset
+        $r zadd zset -100 a
+        $r zadd zset 200 b
+        $r zadd zset -300 c
+        $r zadd zset 1000000 d
+        $r zadd zset +inf max
+        $r zadd zset -inf min
+        $r zrange zset 0 -1
+    } {min c a b d max}
+
     test {EXPIRE - don't set timeouts multiple times} {
         $r set x foobar
         set v1 [$r expire x 5]
@@ -1054,6 +1155,14 @@ proc main {server port} {
         $r save
     } {OK}
 
+    catch {
+        if {[string match {*Darwin*} [exec uname -a]]} {
+            test {Check for memory leaks} {
+                exec leaks redis-server
+            } {*0 leaks*}
+        }
+    }
+
     puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed"
     if {$::failed > 0} {
         puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"