diff options
author | ranshid <88133677+ranshid@users.noreply.github.com> | 2022-09-07 02:54:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-06 16:54:24 -0700 |
commit | c0ce97faccb314f00cdda38a233508d38bd1b855 (patch) | |
tree | 2ac37882ed8539694d698b98abfd0fd2458de11b /tests | |
parent | 3761fdb048e22a5277bd577f87c462dfe019823a (diff) | |
download | redis-c0ce97faccb314f00cdda38a233508d38bd1b855.tar.gz |
fix test Migrate the last slot away from a node using redis-cli (#11221)
When using cli to add node, there can potentially be a race condition in
which all nodes presenting cluster state o.k even though the added node
did not yet meet all cluster nodes.
this adds another utility function to wait until all cluster nodes see the same cluster size
Diffstat (limited to 'tests')
-rw-r--r-- | tests/support/cluster_helper.tcl | 19 | ||||
-rw-r--r-- | tests/unit/cluster/cli.tcl | 5 |
2 files changed, 23 insertions, 1 deletions
diff --git a/tests/support/cluster_helper.tcl b/tests/support/cluster_helper.tcl index 42b99ca83..6d70e44c1 100644 --- a/tests/support/cluster_helper.tcl +++ b/tests/support/cluster_helper.tcl @@ -16,6 +16,16 @@ proc cluster_config_consistent {} { return 1 } +# Check if cluster size is consistent. +proc cluster_size_consistent {cluster_size} { + for {set j 0} {$j < $cluster_size} {incr j} { + if {[CI $j cluster_known_nodes] ne $cluster_size} { + return 0 + } + } + return 1 +} + # Wait for cluster configuration to propagate and be consistent across nodes. proc wait_for_cluster_propagation {} { wait_for_condition 50 100 { @@ -25,6 +35,15 @@ proc wait_for_cluster_propagation {} { } } +# Wait for cluster size to be consistent across nodes. +proc wait_for_cluster_size {cluster_size} { + wait_for_condition 50 100 { + [cluster_size_consistent $cluster_size] eq 1 + } else { + fail "cluster size did not reach a consistent size $cluster_size" + } +} + # Check that cluster nodes agree about "state", or raise an error. proc wait_for_cluster_state {state} { for {set j 0} {$j < [llength $::servers]} {incr j} { diff --git a/tests/unit/cluster/cli.tcl b/tests/unit/cluster/cli.tcl index 6be102309..12da257f6 100644 --- a/tests/unit/cluster/cli.tcl +++ b/tests/unit/cluster/cli.tcl @@ -229,7 +229,10 @@ test {Migrate the last slot away from a node using redis-cli} { exec src/redis-cli --cluster-yes --cluster add-node \ 127.0.0.1:[srv -3 port] \ 127.0.0.1:[srv 0 port] - + + # First we wait for new node to be recognized by entire cluster + wait_for_cluster_size 4 + wait_for_condition 1000 50 { [CI 0 cluster_state] eq {ok} && [CI 1 cluster_state] eq {ok} && |