Skip to content

Commit

Permalink
a few more tests and ability to run a specific test in test-redis.tcl
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Dec 14, 2009
1 parent 49b99ab commit fc77604
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ redis-cli: $(CLIOBJ)
$(CC) -c $(CFLAGS) $(DEBUG) $(COMPILE_TIME) $<

clean:
rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) *.o
rm -rf $(PRGNAME) $(BENCHPRGNAME) $(CLIPRGNAME) *.o *.gcda *.gcno *.gcov

dep:
$(CC) -MM *.c
Expand All @@ -80,5 +80,8 @@ log:
gprof:
make PROF="-pg"

gcov:
make PROF="-fprofile-arcs -ftest-coverage"

32bitgprof:
make PROF="-pg" ARCH="-arch i386"
61 changes: 55 additions & 6 deletions test-redis.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ source redis.tcl

set ::passed 0
set ::failed 0
set ::testnum 0

proc test {name code okpattern} {
puts -nonewline [format "%-70s " $name]
incr ::testnum
if {$::testnum < $::first || $::testnum > $::last} return
puts -nonewline [format "%-70s " "#$::testnum $name"]
flush stdout
set retval [uplevel 1 $code]
if {$okpattern eq $retval || [string match $okpattern $retval]} {
Expand Down Expand Up @@ -53,6 +56,7 @@ proc main {server port} {
set r [redis $server $port]
$r select 9
set err ""
set res ""

# The following AUTH test should be enabled only when requirepass
# <PASSWORD> is set in redis.conf and redis-server was started with
Expand Down Expand Up @@ -925,6 +929,14 @@ proc main {server port} {
list $aux1 $aux2
} {{x y z} {y x z}}

test {ZCARD basics} {
$r zcard ztmp
} {3}

test {ZCARD non existing key} {
$r zcard ztmp-blabla
} {0}

test {ZSCORE} {
set aux {}
set err {}
Expand Down Expand Up @@ -1225,7 +1237,6 @@ proc main {server port} {
if {$::failed > 0} {
puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"
}
close $fd
}

proc stress {} {
Expand Down Expand Up @@ -1262,8 +1273,48 @@ proc stress {} {
$r close
}

# Set a few configuration defaults
set ::host 127.0.0.1
set ::port 6379
set ::stress 0
set ::flush 0
set ::first 0
set ::last 1000000

# Parse arguments
for {set j 0} {$j < [llength $argv]} {incr j} {
set opt [lindex $argv $j]
set arg [lindex $argv [expr $j+1]]
set lastarg [expr {$arg eq {}}]
if {$opt eq {-h} && !$lastarg} {
set ::host $arg
incr j
} elseif {$opt eq {-p} && !$lastarg} {
set ::port $arg
incr j
} elseif {$opt eq {-stress}} {
set ::stress 1
} elseif {$opt eq {--flush}} {
set ::flush 1
} elseif {$opt eq {--first} && !$lastarg} {
set ::first $arg
incr j
} elseif {$opt eq {--last} && !$lastarg} {
set ::last $arg
incr j
} else {
echo "Wrong argument: $opt"
exit 1
}
}

# Before to run the test check if DB 9 and DB 10 are empty
set r [redis]

if {$::flush} {
$r flushall
}

$r select 9
set db9size [$r dbsize]
$r select 10
Expand All @@ -1277,10 +1328,8 @@ unset r
unset db9size
unset db10size

if {[llength $argv] == 0} {
main 127.0.0.1 6379
} elseif {[llength $argv] == 1 && [lindex $argv 0] eq {stress}} {
if {$::stress} {
stress
} else {
main [lindex $argv 0] [lindex $argv 1]
main $::host $::port
}

0 comments on commit fc77604

Please sign in to comment.