Skip to content

Commit

Permalink
Moved test under unit and addressed other comments
Browse files Browse the repository at this point in the history
Signed-off-by: Sankar <[email protected]>
  • Loading branch information
srgsanky committed May 19, 2024
1 parent b826ef7 commit 2ff9879
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3096,7 +3096,7 @@ int clusterProcessPacket(clusterLink *link) {
link->node ? link->node->name : "NULL");

if (sender && (sender->flags & CLUSTER_NODE_MEET)) {
// Once we get a response for MEET from the sender, we can stop sending more MEET
/* Once we get a response for MEET from the sender, we can stop sending more MEET. */
sender->flags &= ~CLUSTER_NODE_MEET;
}

Expand Down
20 changes: 9 additions & 11 deletions tests/cluster/tests/includes/init-tests.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,17 @@ proc join_nodes_in_cluster {} {
return 1
}

if {![info exists do_not_join_cluster_nodes] || !$do_not_join_cluster_nodes} {
test "Cluster Join and auto-discovery test" {
# Use multiple attempts since sometimes nodes timeout
# while attempting to connect.
for {set attempts 3} {$attempts > 0} {incr attempts -1} {
if {[join_nodes_in_cluster] == 1} {
break
}
}
if {$attempts == 0} {
fail "Cluster failed to form full mesh"
test "Cluster Join and auto-discovery test" {
# Use multiple attempts since sometimes nodes timeout
# while attempting to connect.
for {set attempts 3} {$attempts > 0} {incr attempts -1} {
if {[join_nodes_in_cluster] == 1} {
break
}
}
if {$attempts == 0} {
fail "Cluster failed to form full mesh"
}
}

test "Before slots allocation, all nodes report cluster failure" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,55 @@
set do_not_join_cluster_nodes 1
# make sure the test infra won't use SELECT
set old_singledb $::singledb
set ::singledb 1

source "../tests/includes/init-tests.tcl"
tags {tls:skip external:skip cluster} {

# Create a cluster composed of the specified number of primaries.
proc create_primaries_only_cluster {primaries} {
cluster_allocate_slots $primaries
set ::cluster_master_nodes $primaries
set base_conf [list cluster-enabled yes]
start_multiple_servers 2 [list overrides $base_conf] {

test "Cluster nodes are reachable" {
for {set id 0} {$id < [llength $::servers]} {incr id} {
# Every node should be reachable.
wait_for_condition 1000 50 {
([catch {R $id ping} ping_reply] == 0) &&
($ping_reply eq {PONG})
} else {
catch {R $id ping} err
fail "Node #$id keeps replying '$err' to PING."
}
}
}

test "Before slots allocation, all nodes report cluster failure" {
wait_for_cluster_state fail
}

set CLUSTER_PACKET_TYPE_MEET 2
set CLUSTER_PACKET_TYPE_NONE -1

set a 0
set b 1
set b 0
set a 1

test "Cluster nodes haven't met each other" {
assert {[llength [get_cluster_nodes $a]] == 1}
assert {[llength [get_cluster_nodes $b]] == 1}
}

test "Create a 2 nodes cluster with 2 shards" {
create_primaries_only_cluster 2
test "Allocate slots" {
cluster_allocate_slots 2 0
}

test "MEET is reliabile when target drops the initial MEETs" {
set b_port [get_instance_attrib valkey $b port]

# Make b drop the initial MEET messages due to link failure
R $b DEBUG DROP-CLUSTER-PACKET-FILTER $CLUSTER_PACKET_TYPE_MEET
R $b DEBUG CLOSE-CLUSTER-LINK-ON-PACKET-DROP 1

set b_port [srv 0 port]

R $a CLUSTER MEET 127.0.0.1 $b_port

# Wait for at least a few MEETs to be sent so that we are sure that b is
# dropping them.
wait_for_condition 1000 50 {
[CI $b cluster_stats_messages_meet_received] >= 3
} else {
Expand All @@ -46,9 +64,16 @@ test "MEET is reliabile when target drops the initial MEETs" {

# If the MEET is reliable, both a and b will turn to cluster state ok
wait_for_condition 1000 50 {
[CI $a cluster_state] eq {ok} && [CI $b cluster_state] eq {ok}
[CI $a cluster_state] eq {ok} && [CI $b cluster_state] eq {ok} &&
[CI $b cluster_stats_messages_meet_received] >= 4 &&
[CI $a cluster_stats_messages_meet_sent] == [CI $b cluster_stats_messages_meet_received]
} else {
fail "$a cluster_state:[CI $a cluster_state], $b cluster_state: [CI $b cluster_state]"
}
}
} ;# stop servers

} ;# tags

set ::singledb $old_singledb

0 comments on commit 2ff9879

Please sign in to comment.