summaryrefslogtreecommitdiff
path: root/tests/cluster
diff options
context:
space:
mode:
authorHarkrishn Patro <harkrisp@amazon.com>2022-02-11 08:14:27 +0100
committerGitHub <noreply@github.com>2022-02-10 23:14:27 -0800
commita5d17f0b6c85ade94ea04ef7645752398424910c (patch)
tree0ea8d75239d51a186e641e412450e1ecf316fce4 /tests/cluster
parent5bdd72bea77d4bb237441c9a671e80edcdc998ad (diff)
downloadredis-a5d17f0b6c85ade94ea04ef7645752398424910c.tar.gz
Check target node is a primary during cluster setslot. (#10277)
Diffstat (limited to 'tests/cluster')
-rw-r--r--tests/cluster/tests/15-cluster-slots.tcl30
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/cluster/tests/15-cluster-slots.tcl b/tests/cluster/tests/15-cluster-slots.tcl
index f154b7270..93b64b408 100644
--- a/tests/cluster/tests/15-cluster-slots.tcl
+++ b/tests/cluster/tests/15-cluster-slots.tcl
@@ -49,6 +49,34 @@ test "client can handle keys with hash tag" {
$cluster close
}
+test "slot migration is valid from primary to another primary" {
+ set cluster [redis_cluster 127.0.0.1:[get_instance_attrib redis 0 port]]
+ set key order1
+ set slot [$cluster cluster keyslot $key]
+ array set nodefrom [$cluster masternode_for_slot $slot]
+ array set nodeto [$cluster masternode_notfor_slot $slot]
+
+ assert_equal {OK} [$nodefrom(link) cluster setslot $slot node $nodeto(id)]
+ assert_equal {OK} [$nodeto(link) cluster setslot $slot node $nodeto(id)]
+}
+
+test "slot migration is invalid from primary to replica" {
+ set cluster [redis_cluster 127.0.0.1:[get_instance_attrib redis 0 port]]
+ set key order1
+ set slot [$cluster cluster keyslot $key]
+ array set nodefrom [$cluster masternode_for_slot $slot]
+
+ # Get replica node serving slot.
+ set replicanodeinfo [$cluster cluster replicas $nodefrom(id)]
+ puts $replicanodeinfo
+ set args [split $replicanodeinfo " "]
+ set replicaid [lindex [split [lindex $args 0] \{] 1]
+ puts $replicaid
+
+ catch {[$nodefrom(link) cluster setslot $slot node $replicaid]} err
+ assert_match "*Target node is not a master" $err
+}
+
if {$::tls} {
test {CLUSTER SLOTS from non-TLS client in TLS cluster} {
set slots_tls [R 0 cluster slots]
@@ -60,4 +88,4 @@ if {$::tls} {
# Compare the ports in the first row
assert_no_match [lindex $slots_tls 0 3 1] [lindex $slots_plain 0 3 1]
}
-}
+} \ No newline at end of file