From 141bac4c79917675c8b1dd0692413f520ed3b474 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 18 Feb 2014 11:04:01 +0100 Subject: [PATCH] Sentinel test: provide basic commands to access instances. --- tests/sentinel-tests/base.tcl | 9 ++++----- tests/sentinel.tcl | 37 +++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/tests/sentinel-tests/base.tcl b/tests/sentinel-tests/base.tcl index 95626b8b..c148e416 100644 --- a/tests/sentinel-tests/base.tcl +++ b/tests/sentinel-tests/base.tcl @@ -1,6 +1,5 @@ -test "test OK" { -} - -test "test failed" { - assert {"foo" eq "bar"} +test "Sentinels aren't monitoring any master" { + foreach_sentinel_id id { + assert {[S $id sentinel masters] eq {}} + } } diff --git a/tests/sentinel.tcl b/tests/sentinel.tcl index 61cb2828..d8efff6b 100644 --- a/tests/sentinel.tcl +++ b/tests/sentinel.tcl @@ -56,10 +56,11 @@ proc spawn_instance {type base_port count} { } # Push the instance into the right list - lappend ${type}_instances [list \ + lappend ::${type}_instances [list \ + pid $sentinel_pid \ host 127.0.0.1 \ port $port \ - [redis 127.0.0.1 $port] \ + link [redis 127.0.0.1 $port] \ ] } } @@ -115,6 +116,38 @@ proc run_tests {} { } } +# The "S" command is used to interact with the N-th Sentinel. +# The general form is: +# +# S command arg arg arg ... +# +# Example to ping the Sentinel 0 (first instance): S 0 PING +proc S {n args} { + set s [lindex $::sentinel_instances $n] + [dict get $s link] {*}$args +} + +# Like R but to chat with Redis instances. +proc R {n args} { + set r [lindex $::redis_instances $n] + [dict get $r link] {*}$args +} + +# Iterate over IDs of sentinel or redis instances. +proc foreach_sentinel_id {idvar code} { + upvar 1 $idvar id + for {set id 0} {$id < [llength $::sentinel_instances]} {incr id} { + uplevel 1 $code + } +} + +proc foreach_redis_id {idvar code} { + upvar 1 $idvar id + for {set id 0} {$id < [llength $::redis_instances]} {incr id} { + uplevel 1 $code + } +} + if {[catch main e]} { puts $::errorInfo cleanup