Commit bbbe68aa authored by antirez's avatar antirez
Browse files

Sentinel test: provide basic commands to access instances.

parent 6e4662e4
test "test OK" { test "Sentinels aren't monitoring any master" {
} foreach_sentinel_id id {
assert {[S $id sentinel masters] eq {}}
test "test failed" { }
assert {"foo" eq "bar"}
} }
...@@ -56,10 +56,11 @@ proc spawn_instance {type base_port count} { ...@@ -56,10 +56,11 @@ proc spawn_instance {type base_port count} {
} }
# Push the instance into the right list # Push the instance into the right list
lappend ${type}_instances [list \ lappend ::${type}_instances [list \
pid $sentinel_pid \
host 127.0.0.1 \ host 127.0.0.1 \
port $port \ port $port \
[redis 127.0.0.1 $port] \ link [redis 127.0.0.1 $port] \
] ]
} }
} }
...@@ -115,6 +116,38 @@ proc run_tests {} { ...@@ -115,6 +116,38 @@ proc run_tests {} {
} }
} }
# The "S" command is used to interact with the N-th Sentinel.
# The general form is:
#
# S <sentinel-id> 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]} { if {[catch main e]} {
puts $::errorInfo puts $::errorInfo
cleanup cleanup
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment