From d7da507683028e6bb7b53220f85b574e4a51dce9 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 20 Feb 2014 16:57:51 +0100 Subject: [PATCH] Sentinel test: move init tests as includes. Most units will start with these two basic tests to create an environment where the real tests are ran. --- tests/sentinel-tests/00-base.tcl | 26 +------------------- tests/sentinel-tests/includes/init-tests.tcl | 23 +++++++++++++++++ tests/sentinel.tcl | 1 + 3 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 tests/sentinel-tests/includes/init-tests.tcl diff --git a/tests/sentinel-tests/00-base.tcl b/tests/sentinel-tests/00-base.tcl index 8788cfdb..0587c625 100644 --- a/tests/sentinel-tests/00-base.tcl +++ b/tests/sentinel-tests/00-base.tcl @@ -1,30 +1,6 @@ # Check the basic monitoring and failover capabilities. -test "Sentinels aren't monitoring any master" { - foreach_sentinel_id id { - assert {[S $id sentinel masters] eq {}} - } -} - -set redis_slaves 4 -test "Create a master-slaves cluster of [expr $redis_slaves+1] instances" { - create_redis_master_slave_cluster [expr {$redis_slaves+1}] -} -set master_id 0 - -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 - } - foreach_sentinel_id id { - assert {[S $id sentinel master mymaster] ne {}} - } -} +source "../sentinel-tests/includes/init-tests.tcl" test "Sentinels are able to auto-discover other sentinels" { set sentinels [llength $::sentinel_instances] diff --git a/tests/sentinel-tests/includes/init-tests.tcl b/tests/sentinel-tests/includes/init-tests.tcl new file mode 100644 index 00000000..302f64b6 --- /dev/null +++ b/tests/sentinel-tests/includes/init-tests.tcl @@ -0,0 +1,23 @@ +# Initialization tests -- most units will start including this. + +set redis_slaves 4 +test "Create a master-slaves cluster of [expr $redis_slaves+1] instances" { + create_redis_master_slave_cluster [expr {$redis_slaves+1}] +} +set master_id 0 + +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 + } + foreach_sentinel_id id { + assert {[S $id sentinel master mymaster] ne {}} + } +} + + diff --git a/tests/sentinel.tcl b/tests/sentinel.tcl index 54464355..4b49ed4c 100644 --- a/tests/sentinel.tcl +++ b/tests/sentinel.tcl @@ -141,6 +141,7 @@ proc run_tests {} { if {$::run_matching ne {} && [string match $::run_matching $test] == 0} { continue } + if {[file isdirectory $test]} continue puts [colorstr yellow "Testing unit: [lindex [file split $test] end]"] source $test }