From 57654444542b54e178b07fa904aee8b019f3a9c9 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 20 Feb 2014 16:28:38 +0100 Subject: [PATCH] Sentinel test: ability to run just a subset of test files. --- tests/sentinel-tests/00-base.tcl | 1 + tests/sentinel.tcl | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tests/sentinel-tests/00-base.tcl b/tests/sentinel-tests/00-base.tcl index 8fc20775..8788cfdb 100644 --- a/tests/sentinel-tests/00-base.tcl +++ b/tests/sentinel-tests/00-base.tcl @@ -16,6 +16,7 @@ test "Sentinels can start monitoring a master" { set sentinels [llength $::sentinel_instances] set quorum [expr {$sentinels/2+1}] foreach_sentinel_id id { + catch {S $id SENTINEL REMOVE mymaster} S $id SENTINEL MONITOR mymaster \ [get_instance_attrib redis $master_id host] \ [get_instance_attrib redis $master_id port] $quorum diff --git a/tests/sentinel.tcl b/tests/sentinel.tcl index 0001a15f..54464355 100644 --- a/tests/sentinel.tcl +++ b/tests/sentinel.tcl @@ -18,6 +18,7 @@ set ::redis_base_port 30000 set ::instances_count 5 ; # How many Sentinels / Instances we use at max set ::pids {} ; # We kill everything at exit set ::dirs {} ; # We remove all the temp dirs at exit +set ::run_matching {} ; # If non empty, only tests matching pattern are run. if {[catch {cd tests/sentinel-tmp}]} { puts "tests/sentinel-tmp directory not found." @@ -87,7 +88,28 @@ proc abort_sentinel_test msg { exit 1 } +proc parse_options {} { + for {set j 0} {$j < [llength $::argv]} {incr j} { + set opt [lindex $::argv $j] + set val [lindex $::argv [expr $j+1]] + if {$opt eq "--single"} { + incr j + set ::run_matching "*${val}*" + } elseif {$opt eq "--help"} { + puts "Hello, I'm sentinel.tcl and I run Sentinel unit tests." + puts "\nOptions:" + puts "--single Only runs tests specified by pattern." + puts "--help Shows this help." + exit 0 + } else { + puts "Unknown option $opt" + exit 1 + } + } +} + proc main {} { + parse_options spawn_instance sentinel $::sentinel_base_port $::instances_count spawn_instance redis $::redis_base_port $::instances_count run_tests @@ -116,6 +138,9 @@ proc test {descr code} { proc run_tests {} { set tests [lsort [glob ../sentinel-tests/*]] foreach test $tests { + if {$::run_matching ne {} && [string match $::run_matching $test] == 0} { + continue + } puts [colorstr yellow "Testing unit: [lindex [file split $test] end]"] source $test }