Cluster test: better failure detection test and framework improvements.

This commit is contained in:
antirez 2014-05-19 15:26:17 +02:00
parent a7da78e472
commit 194b78050e
2 changed files with 43 additions and 9 deletions

View File

@ -73,3 +73,36 @@ proc assert_cluster_state {state} {
} }
} }
} }
# Search the first node starting from ID $first that is not
# already configured as a slave.
proc cluster_find_available_slave {first} {
foreach_redis_id id {
if {$id < $first} continue
if {[instance_is_killed redis $id]} continue
set me [get_myself $id]
if {[dict get $me slaveof] eq {-}} {return $id}
}
fail "No available slaves"
}
# Add 'slaves' slaves to a cluster composed of 'masters' masters.
# It assumes that masters are allocated sequentially from instance ID 0
# to N-1.
proc cluster_allocate_slaves {masters slaves} {
for {set j 0} {$j < $slaves} {incr j} {
set master_id [expr {$j % $masters}]
set slave_id [cluster_find_available_slave $masters]
set master_myself [get_myself $master_id]
R $slave_id cluster replicate [dict get $master_myself id]
}
}
# Create a cluster composed of the specified number of masters and slaves.
proc create_cluster {masters slaves} {
cluster_allocate_slots $masters
if {$slaves} {
cluster_allocate_slaves $masters $slaves
}
assert_cluster_state ok
}

View File

@ -2,16 +2,8 @@
source "../tests/includes/init-tests.tcl" source "../tests/includes/init-tests.tcl"
proc create_cluster {masters slaves} {
cluster_allocate_slots $masters
if {$slaves} {
cluster_allocate_slaves $masters $slaves
}
assert_cluster_state ok
}
test "Create a 5 nodes cluster" { test "Create a 5 nodes cluster" {
create_cluster 5 0 create_cluster 5 5
} }
test "Killing one master node" { test "Killing one master node" {
@ -29,3 +21,12 @@ test "Restarting master node" {
test "Cluster should be up again" { test "Cluster should be up again" {
assert_cluster_state ok assert_cluster_state ok
} }
test "Killing two slave nodes" {
kill_instance redis 5
kill_instance redis 6
}
test "Cluster should be still up" {
assert_cluster_state ok
}