Avoid false positive in election tests (#984)

The node may not be able to initiate an election in time due to
problems with cluster communication. If an election is initiated,
make sure its offset is 0.

Closes #967.

Signed-off-by: Binbin <binloveplay1314@qq.com>
Signed-off-by: Ping Xie <pingxie@google.com>
This commit is contained in:
Binbin 2024-09-13 14:53:39 +08:00 committed by Ping Xie
parent d4e6546f7c
commit 09ed2fccca
2 changed files with 34 additions and 8 deletions

View File

@ -227,6 +227,15 @@ proc cluster_setup {masters replicas node_count slot_allocator replica_allocator
# Setup master/replica relationships
$replica_allocator $masters $replicas
# A helper debug log that can print the server id in the server logs.
# This can help us locate the corresponding server in the log file.
for {set i 0} {$i < $masters} {incr i} {
R $i DEBUG LOG "========== I am primary $i =========="
}
for {set i $i} {$i < [expr $masters+$replicas]} {incr i} {
R $i DEBUG LOG "========== I am replica $i =========="
}
wait_for_cluster_propagation
wait_for_cluster_state "ok"

View File

@ -75,9 +75,15 @@ proc test_migrated_replica {type} {
fail "Failover does not happened"
}
# Make sure the offset of server 3 / 7 is 0.
verify_log_message -3 "*Start of election*offset 0*" 0
verify_log_message -7 "*Start of election*offset 0*" 0
# The node may not be able to initiate an election in time due to
# problems with cluster communication. If an election is initiated,
# we make sure the offset of server 3 / 7 is 0.
if {[count_log_message -3 "Start of election"] != 0} {
verify_log_message -3 "*Start of election*offset 0*" 0
}
if {[count_log_message -7 "Start of election"] != 0} {
verify_log_message -7 "*Start of election*offset 0*" 0
}
# Make sure the right replica gets the higher rank.
verify_log_message -4 "*Start of election*rank #0*" 0
@ -170,9 +176,14 @@ proc test_nonempty_replica {type} {
fail "Failover does not happened"
}
# Make sure server 7 gets the lower rank and it's offset is 0.
verify_log_message -4 "*Start of election*rank #0*" 0
verify_log_message -7 "*Start of election*offset 0*" 0
# The node may not be able to initiate an election in time due to
# problems with cluster communication. If an election is initiated,
# we make sure server 7 gets the lower rank and it's offset is 0.
if {[count_log_message -7 "Start of election"] != 0} {
verify_log_message -7 "*Start of election*offset 0*" 0
}
# Wait for the cluster to be ok.
wait_for_condition 1000 50 {
@ -283,9 +294,15 @@ proc test_sub_replica {type} {
fail "Failover does not happened"
}
# Make sure the offset of server 3 / 7 is 0.
verify_log_message -3 "*Start of election*offset 0*" 0
verify_log_message -7 "*Start of election*offset 0*" 0
# The node may not be able to initiate an election in time due to
# problems with cluster communication. If an election is initiated,
# we make sure the offset of server 3 / 7 is 0.
if {[count_log_message -3 "Start of election"] != 0} {
verify_log_message -3 "*Start of election*offset 0*" 0
}
if {[count_log_message -7 "Start of election"] != 0} {
verify_log_message -7 "*Start of election*offset 0*" 0
}
# Wait for the cluster to be ok.
wait_for_condition 1000 50 {