Skip to content

Commit

Permalink
adjust the test
Browse files Browse the repository at this point in the history
Signed-off-by: Binbin <[email protected]>
  • Loading branch information
enjoy-binbin committed Jul 12, 2024
1 parent 86e7032 commit a09417c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -4095,8 +4095,9 @@ void clusterSendFailoverAuthIfNeeded(clusterNode *node, clusterMsg *request) {
* replication offset, and so forth. Note that because how the rank is computed
* multiple replicas may have the same rank, in case they have the same offset.
*
* If the replication offsets are the same, the one with the smaller node id
* will have a better ranking to avoid simultaneous elections of replicas.
* If the replication offsets are the same, the one with the lexicographically
* smaller Node id * will have a better ranking to avoid simultaneous elections
* of replicas.
*
* The replica rank is used to add a delay to start an election in order to
* get voted and replace a failing primary. Replicas with better replication
Expand Down
7 changes: 6 additions & 1 deletion tests/support/util.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,16 @@ proc count_log_message {srv_idx pattern} {
return [count_message_lines $stdout $pattern]
}

# verify pattern exists in server's sdtout after a certain line number
# verify pattern exists in server's stdout after a certain line number
proc verify_log_message {srv_idx pattern from_line} {
incr from_line
set result [exec tail -n +$from_line < [srv $srv_idx stdout]]
if {![string match $pattern $result]} {
puts "logs ====1===="
puts $pattern
puts $srv_idx
puts $result
puts "logs ====2===="
error "assertion:expected message not found in log file: $pattern"
}
}
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/cluster/failover.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,7 @@ test "Instance #0 gets converted into a slave" {

} ;# start_cluster

# Add all replicas to the first primary node.
proc cluster_allocate_replicas_to_one_primary {primaries replicas} {
set primary_id 0
for {set j 0} {$j < $replicas} {incr j} {
set replica_id [cluster_find_available_replica $primaries]
set primary_myself [cluster_get_myself $primary_id]
R $replica_id cluster replicate [dict get $primary_myself id]
}
}

start_cluster 5 10 {tags {external:skip cluster} overrides {cluster-node-timeout 5000}} {
start_cluster 3 6 {tags {external:skip cluster}} {

test "Cluster is up" {
wait_for_cluster_state ok
Expand Down Expand Up @@ -130,4 +120,14 @@ test "Instance #0 gets converted into a replica" {
wait_for_cluster_propagation
}

} continuous_slot_allocation cluster_allocate_replicas_to_one_primary ;# start_cluster
test "Make sure the replicas always get the different ranks" {
if {[s -3 role] == "master"} {
verify_log_message -3 "*Start of election*rank #0*" 0
verify_log_message -6 "*Start of election*rank #1*" 0
} else {
verify_log_message -3 "*Start of election*rank #1*" 0
verify_log_message -6 "*Start of election*rank #0*" 0
}
}

} ;# start_cluster

0 comments on commit a09417c

Please sign in to comment.