Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
194b7805
Commit
194b7805
authored
May 19, 2014
by
antirez
Browse files
Cluster test: better failure detection test and framework improvements.
parent
a7da78e4
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/cluster/cluster.tcl
View file @
194b7805
...
...
@@ -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
}
tests/cluster/tests/01-faildet.tcl
View file @
194b7805
...
...
@@ -2,16 +2,8 @@
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"
{
create_cluster 5
0
create_cluster 5
5
}
test
"Killing one master node"
{
...
...
@@ -29,3 +21,12 @@ test "Restarting master node" {
test
"Cluster should be up again"
{
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment