Skip to content

Commit

Permalink
Addressed comments about the unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Sankar <[email protected]>
  • Loading branch information
srgsanky committed May 20, 2024
1 parent ec68829 commit a760aa6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 65 deletions.
1 change: 0 additions & 1 deletion tests/cluster/tests/includes/init-tests.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ test "Cluster nodes hard reset" {
R $id config set repl-diskless-load disabled
R $id config set cluster-announce-hostname ""
R $id DEBUG DROP-CLUSTER-PACKET-FILTER -1
R $id DEBUG CLOSE-CLUSTER-LINK-ON-PACKET-DROP 0
R $id config rewrite
}
}
Expand Down
120 changes: 56 additions & 64 deletions tests/unit/cluster/cluster-reliable-meet.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,68 @@ set old_singledb $::singledb
set ::singledb 1

tags {tls:skip external:skip cluster} {

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."
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 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 "Allocate slots" {
cluster_allocate_slots 2 0
}

test "MEET is reliabile when target drops the initial MEETs" {
# 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 {
fail "Cluster node $a never sent multiple MEETs to $b"
}
test "Before slots allocation, all nodes report cluster failure" {
wait_for_cluster_state fail
}

# Make sure the nodes still don't know about each other
assert {[llength [get_cluster_nodes $a connected]] == 1}
assert {[llength [get_cluster_nodes $b connected]] == 1}
set CLUSTER_PACKET_TYPE_MEET 2
set CLUSTER_PACKET_TYPE_NONE -1

R $b DEBUG DROP-CLUSTER-PACKET-FILTER $CLUSTER_PACKET_TYPE_NONE
test "Cluster nodes haven't met each other" {
assert {[llength [get_cluster_nodes 1]] == 1}
assert {[llength [get_cluster_nodes 0]] == 1}
}

# 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 $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
test "Allocate slots" {
cluster_allocate_slots 2 0
}

test "MEET is reliabile when target drops the initial MEETs" {
# Make 0 drop the initial MEET messages due to link failure
R 0 DEBUG DROP-CLUSTER-PACKET-FILTER $CLUSTER_PACKET_TYPE_MEET
R 0 DEBUG CLOSE-CLUSTER-LINK-ON-PACKET-DROP 1

R 1 CLUSTER MEET 127.0.0.1 [srv 0 port]

# Wait for at least a few MEETs to be sent so that we are sure that 0 is
# dropping them.
wait_for_condition 1000 50 {
[CI 0 cluster_stats_messages_meet_received] >= 3
} else {
fail "Cluster node $a never sent multiple MEETs to $b"
}

# Make sure the nodes still don't know about each other
assert {[llength [get_cluster_nodes 1 connected]] == 1}
assert {[llength [get_cluster_nodes 0 connected]] == 1}

R 0 DEBUG DROP-CLUSTER-PACKET-FILTER $CLUSTER_PACKET_TYPE_NONE

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

set ::singledb $old_singledb
Expand Down

0 comments on commit a760aa6

Please sign in to comment.