summaryrefslogtreecommitdiff
path: root/tests/cluster
diff options
context:
space:
mode:
authorMadelyn Olson <34459052+madolson@users.noreply.github.com>2022-07-12 10:41:29 -0700
committerGitHub <noreply@github.com>2022-07-12 10:41:29 -0700
commit8a4e3bcd8d26a50c6d5f4417102f71f8e2e2d70d (patch)
treead810090a14fcd18628bf45321e8771904583471 /tests/cluster
parent8221d481656e3bc109d85dd6523e723d63024ae6 (diff)
downloadredis-8a4e3bcd8d26a50c6d5f4417102f71f8e2e2d70d.tar.gz
Cluster test improvements (#10920)
* Restructured testing to allow running cluster tests easily as part of the normal testing
Diffstat (limited to 'tests/cluster')
-rw-r--r--tests/cluster/tests/00-base.tcl19
-rw-r--r--tests/cluster/tests/23-multiple-slot-operations.tcl115
-rw-r--r--tests/cluster/tests/27-endpoints.tcl219
3 files changed, 0 insertions, 353 deletions
diff --git a/tests/cluster/tests/00-base.tcl b/tests/cluster/tests/00-base.tcl
index e9e99baaa..08ecd5e4a 100644
--- a/tests/cluster/tests/00-base.tcl
+++ b/tests/cluster/tests/00-base.tcl
@@ -63,24 +63,6 @@ test "It is possible to write and read from the cluster" {
cluster_write_test 0
}
-test "Function no-cluster flag" {
- R 1 function load {#!lua name=test
- redis.register_function{function_name='f1', callback=function() return 'hello' end, flags={'no-cluster'}}
- }
- catch {R 1 fcall f1 0} e
- assert_match {*Can not run script on cluster, 'no-cluster' flag is set*} $e
-}
-
-test "Script no-cluster flag" {
- catch {
- R 1 eval {#!lua flags=no-cluster
- return 1
- } 0
- } e
-
- assert_match {*Can not run script on cluster, 'no-cluster' flag is set*} $e
-}
-
test "CLUSTER RESET SOFT test" {
set last_epoch_node0 [get_info_field [R 0 cluster info] cluster_current_epoch]
R 0 FLUSHALL
@@ -92,4 +74,3 @@ test "CLUSTER RESET SOFT test" {
R 1 CLUSTER RESET SOFT
assert {[get_info_field [R 1 cluster info] cluster_current_epoch] eq $last_epoch_node1}
}
-
diff --git a/tests/cluster/tests/23-multiple-slot-operations.tcl b/tests/cluster/tests/23-multiple-slot-operations.tcl
deleted file mode 100644
index 060ab577a..000000000
--- a/tests/cluster/tests/23-multiple-slot-operations.tcl
+++ /dev/null
@@ -1,115 +0,0 @@
-# Check the multiple slot add and remove commands
-
-source "../tests/includes/init-tests.tcl"
-
-proc cluster_allocate_with_continuous_slots_local {n} {
- R 0 cluster ADDSLOTSRANGE 0 3276
- R 1 cluster ADDSLOTSRANGE 3277 6552
- R 2 cluster ADDSLOTSRANGE 6553 9828
- R 3 cluster ADDSLOTSRANGE 9829 13104
- R 4 cluster ADDSLOTSRANGE 13105 16383
-}
-
-proc cluster_create_with_continuous_slots_local {masters slaves} {
- cluster_allocate_with_continuous_slots_local $masters
- if {$slaves} {
- cluster_allocate_slaves $masters $slaves
- }
- assert_cluster_state ok
-}
-
-
-test "Create a 5 nodes cluster" {
- cluster_create_with_continuous_slots_local 5 5
-}
-
-test "Cluster should start ok" {
- assert_cluster_state ok
-}
-
-set master1 [Rn 0]
-set master2 [Rn 1]
-set master3 [Rn 2]
-set master4 [Rn 3]
-set master5 [Rn 4]
-
-test "Continuous slots distribution" {
- assert_match "* 0-3276*" [$master1 CLUSTER NODES]
- assert_match "* 3277-6552*" [$master2 CLUSTER NODES]
- assert_match "* 6553-9828*" [$master3 CLUSTER NODES]
- assert_match "* 9829-13104*" [$master4 CLUSTER NODES]
- assert_match "* 13105-16383*" [$master5 CLUSTER NODES]
- assert_match "*0 3276*" [$master1 CLUSTER SLOTS]
- assert_match "*3277 6552*" [$master2 CLUSTER SLOTS]
- assert_match "*6553 9828*" [$master3 CLUSTER SLOTS]
- assert_match "*9829 13104*" [$master4 CLUSTER SLOTS]
- assert_match "*13105 16383*" [$master5 CLUSTER SLOTS]
-
- $master1 CLUSTER DELSLOTSRANGE 3001 3050
- assert_match "* 0-3000 3051-3276*" [$master1 CLUSTER NODES]
- assert_match "*0 3000*3051 3276*" [$master1 CLUSTER SLOTS]
-
- $master2 CLUSTER DELSLOTSRANGE 5001 5500
- assert_match "* 3277-5000 5501-6552*" [$master2 CLUSTER NODES]
- assert_match "*3277 5000*5501 6552*" [$master2 CLUSTER SLOTS]
-
- $master3 CLUSTER DELSLOTSRANGE 7001 7100 8001 8500
- assert_match "* 6553-7000 7101-8000 8501-9828*" [$master3 CLUSTER NODES]
- assert_match "*6553 7000*7101 8000*8501 9828*" [$master3 CLUSTER SLOTS]
-
- $master4 CLUSTER DELSLOTSRANGE 11001 12000 12101 12200
- assert_match "* 9829-11000 12001-12100 12201-13104*" [$master4 CLUSTER NODES]
- assert_match "*9829 11000*12001 12100*12201 13104*" [$master4 CLUSTER SLOTS]
-
- $master5 CLUSTER DELSLOTSRANGE 13501 14000 15001 16000
- assert_match "* 13105-13500 14001-15000 16001-16383*" [$master5 CLUSTER NODES]
- assert_match "*13105 13500*14001 15000*16001 16383*" [$master5 CLUSTER SLOTS]
-}
-
-test "ADDSLOTSRANGE command with several boundary conditions test suite" {
- # Add multiple slots with incorrect argument number
- assert_error "ERR wrong number of arguments for 'cluster|addslotsrange' command" {R 0 cluster ADDSLOTSRANGE 3001 3020 3030}
-
- # Add multiple slots with invalid input slot
- assert_error "ERR Invalid or out of range slot" {R 0 cluster ADDSLOTSRANGE 3001 3020 3030 aaa}
- assert_error "ERR Invalid or out of range slot" {R 0 cluster ADDSLOTSRANGE 3001 3020 3030 70000}
- assert_error "ERR Invalid or out of range slot" {R 0 cluster ADDSLOTSRANGE 3001 3020 -1000 3030}
-
- # Add multiple slots when start slot number is greater than the end slot
- assert_error "ERR start slot number 3030 is greater than end slot number 3025" {R 0 cluster ADDSLOTSRANGE 3001 3020 3030 3025}
-
- # Add multiple slots with busy slot
- assert_error "ERR Slot 3200 is already busy" {R 0 cluster ADDSLOTSRANGE 3001 3020 3200 3250}
-
- # Add multiple slots with assigned multiple times
- assert_error "ERR Slot 3001 specified multiple times" {R 0 cluster ADDSLOTSRANGE 3001 3020 3001 3020}
-}
-
-test "DELSLOTSRANGE command with several boundary conditions test suite" {
- # Delete multiple slots with incorrect argument number
- assert_error "ERR wrong number of arguments for 'cluster|delslotsrange' command" {R 0 cluster DELSLOTSRANGE 1000 2000 2100}
- assert_match "* 0-3000 3051-3276*" [$master1 CLUSTER NODES]
- assert_match "*0 3000*3051 3276*" [$master1 CLUSTER SLOTS]
-
- # Delete multiple slots with invalid input slot
- assert_error "ERR Invalid or out of range slot" {R 0 cluster DELSLOTSRANGE 1000 2000 2100 aaa}
- assert_error "ERR Invalid or out of range slot" {R 0 cluster DELSLOTSRANGE 1000 2000 2100 70000}
- assert_error "ERR Invalid or out of range slot" {R 0 cluster DELSLOTSRANGE 1000 2000 -2100 2200}
- assert_match "* 0-3000 3051-3276*" [$master1 CLUSTER NODES]
- assert_match "*0 3000*3051 3276*" [$master1 CLUSTER SLOTS]
-
- # Delete multiple slots when start slot number is greater than the end slot
- assert_error "ERR start slot number 5800 is greater than end slot number 5750" {R 1 cluster DELSLOTSRANGE 5600 5700 5800 5750}
- assert_match "* 3277-5000 5501-6552*" [$master2 CLUSTER NODES]
- assert_match "*3277 5000*5501 6552*" [$master2 CLUSTER SLOTS]
-
- # Delete multiple slots with already unassigned
- assert_error "ERR Slot 7001 is already unassigned" {R 2 cluster DELSLOTSRANGE 7001 7100 9000 9200}
- assert_match "* 6553-7000 7101-8000 8501-9828*" [$master3 CLUSTER NODES]
- assert_match "*6553 7000*7101 8000*8501 9828*" [$master3 CLUSTER SLOTS]
-
- # Delete multiple slots with assigned multiple times
- assert_error "ERR Slot 12500 specified multiple times" {R 3 cluster DELSLOTSRANGE 12500 12600 12500 12600}
- assert_match "* 9829-11000 12001-12100 12201-13104*" [$master4 CLUSTER NODES]
- assert_match "*9829 11000*12001 12100*12201 13104*" [$master4 CLUSTER SLOTS]
-}
diff --git a/tests/cluster/tests/27-endpoints.tcl b/tests/cluster/tests/27-endpoints.tcl
deleted file mode 100644
index 32e3e794d..000000000
--- a/tests/cluster/tests/27-endpoints.tcl
+++ /dev/null
@@ -1,219 +0,0 @@
-source "../tests/includes/init-tests.tcl"
-
-# Isolate a node from the cluster and give it a new nodeid
-proc isolate_node {id} {
- set node_id [R $id CLUSTER MYID]
- R 6 CLUSTER RESET HARD
- for {set j 0} {$j < 20} {incr j} {
- if { $j eq $id } {
- continue
- }
- R $j CLUSTER FORGET $node_id
- }
-}
-
-proc get_slot_field {slot_output shard_id node_id attrib_id} {
- return [lindex [lindex [lindex $slot_output $shard_id] $node_id] $attrib_id]
-}
-
-test "Create a 6 nodes cluster" {
- cluster_create_with_continuous_slots 3 3
-}
-
-test "Cluster should start ok" {
- assert_cluster_state ok
- wait_for_cluster_propagation
-}
-
-test "Set cluster hostnames and verify they are propagated" {
- for {set j 0} {$j < $::cluster_master_nodes + $::cluster_replica_nodes} {incr j} {
- R $j config set cluster-announce-hostname "host-$j.com"
- }
-
- wait_for_condition 50 100 {
- [are_hostnames_propagated "host-*.com"] eq 1
- } else {
- fail "cluster hostnames were not propagated"
- }
-
- # Now that everything is propagated, assert everyone agrees
- wait_for_cluster_propagation
-}
-
-test "Update hostnames and make sure they are all eventually propagated" {
- for {set j 0} {$j < $::cluster_master_nodes + $::cluster_replica_nodes} {incr j} {
- R $j config set cluster-announce-hostname "host-updated-$j.com"
- }
-
- wait_for_condition 50 100 {
- [are_hostnames_propagated "host-updated-*.com"] eq 1
- } else {
- fail "cluster hostnames were not propagated"
- }
-
- # Now that everything is propagated, assert everyone agrees
- wait_for_cluster_propagation
-}
-
-test "Remove hostnames and make sure they are all eventually propagated" {
- for {set j 0} {$j < $::cluster_master_nodes + $::cluster_replica_nodes} {incr j} {
- R $j config set cluster-announce-hostname ""
- }
-
- wait_for_condition 50 100 {
- [are_hostnames_propagated ""] eq 1
- } else {
- fail "cluster hostnames were not propagated"
- }
-
- # Now that everything is propagated, assert everyone agrees
- wait_for_cluster_propagation
-}
-
-test "Verify cluster-preferred-endpoint-type behavior for redirects and info" {
- R 0 config set cluster-announce-hostname "me.com"
- R 1 config set cluster-announce-hostname ""
- R 2 config set cluster-announce-hostname "them.com"
-
- wait_for_cluster_propagation
-
- # Verify default behavior
- set slot_result [R 0 cluster slots]
- assert_equal "" [lindex [get_slot_field $slot_result 0 2 0] 1]
- assert_equal "" [lindex [get_slot_field $slot_result 2 2 0] 1]
- assert_equal "hostname" [lindex [get_slot_field $slot_result 0 2 3] 0]
- assert_equal "me.com" [lindex [get_slot_field $slot_result 0 2 3] 1]
- assert_equal "hostname" [lindex [get_slot_field $slot_result 2 2 3] 0]
- assert_equal "them.com" [lindex [get_slot_field $slot_result 2 2 3] 1]
-
- # Redirect will use the IP address
- catch {R 0 set foo foo} redir_err
- assert_match "MOVED * 127.0.0.1:*" $redir_err
-
- # Verify prefer hostname behavior
- R 0 config set cluster-preferred-endpoint-type hostname
-
- set slot_result [R 0 cluster slots]
- assert_equal "me.com" [get_slot_field $slot_result 0 2 0]
- assert_equal "them.com" [get_slot_field $slot_result 2 2 0]
-
- # Redirect should use hostname
- catch {R 0 set foo foo} redir_err
- assert_match "MOVED * them.com:*" $redir_err
-
- # Redirect to an unknown hostname returns ?
- catch {R 0 set barfoo bar} redir_err
- assert_match "MOVED * ?:*" $redir_err
-
- # Verify unknown hostname behavior
- R 0 config set cluster-preferred-endpoint-type unknown-endpoint
-
- # Verify default behavior
- set slot_result [R 0 cluster slots]
- assert_equal "ip" [lindex [get_slot_field $slot_result 0 2 3] 0]
- assert_equal "127.0.0.1" [lindex [get_slot_field $slot_result 0 2 3] 1]
- assert_equal "ip" [lindex [get_slot_field $slot_result 2 2 3] 0]
- assert_equal "127.0.0.1" [lindex [get_slot_field $slot_result 2 2 3] 1]
- assert_equal "ip" [lindex [get_slot_field $slot_result 1 2 3] 0]
- assert_equal "127.0.0.1" [lindex [get_slot_field $slot_result 1 2 3] 1]
- # Not required by the protocol, but IP comes before hostname
- assert_equal "hostname" [lindex [get_slot_field $slot_result 0 2 3] 2]
- assert_equal "me.com" [lindex [get_slot_field $slot_result 0 2 3] 3]
- assert_equal "hostname" [lindex [get_slot_field $slot_result 2 2 3] 2]
- assert_equal "them.com" [lindex [get_slot_field $slot_result 2 2 3] 3]
-
- # This node doesn't have a hostname
- assert_equal 2 [llength [get_slot_field $slot_result 1 2 3]]
-
- # Redirect should use empty string
- catch {R 0 set foo foo} redir_err
- assert_match "MOVED * :*" $redir_err
-
- R 0 config set cluster-preferred-endpoint-type ip
-}
-
-test "Verify the nodes configured with prefer hostname only show hostname for new nodes" {
- # Have everyone forget node 6 and isolate it from the cluster.
- isolate_node 6
-
- # Set hostnames for the primaries, now that the node is isolated
- R 0 config set cluster-announce-hostname "shard-1.com"
- R 1 config set cluster-announce-hostname "shard-2.com"
- R 2 config set cluster-announce-hostname "shard-3.com"
-
- # Prevent Node 0 and Node 6 from properly meeting,
- # they'll hang in the handshake phase. This allows us to
- # test the case where we "know" about it but haven't
- # successfully retrieved information about it yet.
- R 0 DEBUG DROP-CLUSTER-PACKET-FILTER 0
- R 6 DEBUG DROP-CLUSTER-PACKET-FILTER 0
-
- # Have a replica meet the isolated node
- R 3 cluster meet 127.0.0.1 [get_instance_attrib redis 6 port]
-
- # Wait for the isolated node to learn about the rest of the cluster,
- # which correspond to a single entry in cluster nodes. Note this
- # doesn't mean the isolated node has successfully contacted each
- # node.
- wait_for_condition 50 100 {
- [llength [split [R 6 CLUSTER NODES] "\n"]] eq 21
- } else {
- fail "Isolated node didn't learn about the rest of the cluster *"
- }
-
- # Now, we wait until the two nodes that aren't filtering packets
- # to accept our isolated nodes connections. At this point they will
- # start showing up in cluster slots.
- wait_for_condition 50 100 {
- [llength [R 6 CLUSTER SLOTS]] eq 2
- } else {
- fail "Node did not learn about the 2 shards it can talk to"
- }
- set slot_result [R 6 CLUSTER SLOTS]
- assert_equal [lindex [get_slot_field $slot_result 0 2 3] 1] "shard-2.com"
- assert_equal [lindex [get_slot_field $slot_result 1 2 3] 1] "shard-3.com"
-
- # Also make sure we know about the isolated primary, we
- # just can't reach it.
- set primary_id [R 0 CLUSTER MYID]
- assert_match "*$primary_id*" [R 6 CLUSTER NODES]
-
- # Stop dropping cluster packets, and make sure everything
- # stabilizes
- R 0 DEBUG DROP-CLUSTER-PACKET-FILTER -1
- R 6 DEBUG DROP-CLUSTER-PACKET-FILTER -1
-
- wait_for_condition 50 100 {
- [llength [R 6 CLUSTER SLOTS]] eq 3
- } else {
- fail "Node did not learn about the 2 shards it can talk to"
- }
- set slot_result [R 6 CLUSTER SLOTS]
- assert_equal [lindex [get_slot_field $slot_result 0 2 3] 1] "shard-1.com"
- assert_equal [lindex [get_slot_field $slot_result 1 2 3] 1] "shard-2.com"
- assert_equal [lindex [get_slot_field $slot_result 2 2 3] 1] "shard-3.com"
-}
-
-test "Test restart will keep hostname information" {
- # Set a new hostname, reboot and make sure it sticks
- R 0 config set cluster-announce-hostname "restart-1.com"
- # Store the hostname in the config
- R 0 config rewrite
- kill_instance redis 0
- restart_instance redis 0
- set slot_result [R 0 CLUSTER SLOTS]
- assert_equal [lindex [get_slot_field $slot_result 0 2 3] 1] "restart-1.com"
-
- # As a sanity check, make sure everyone eventually agrees
- wait_for_cluster_propagation
-}
-
-test "Test hostname validation" {
- catch {R 0 config set cluster-announce-hostname [string repeat x 256]} err
- assert_match "*Hostnames must be less than 256 characters*" $err
- catch {R 0 config set cluster-announce-hostname "?.com"} err
- assert_match "*Hostnames may only contain alphanumeric characters, hyphens or dots*" $err
-
- # Note this isn't a valid hostname, but it passes our internal validation
- R 0 config set cluster-announce-hostname "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-."
-} \ No newline at end of file