Fix race condition in cluster test 22-replica-in-sync (#9721)

there was a chance that by the time the assertion is executed,
the replica already manages to reconnect.

now we make sure the replica is unable to re-connect to the master.

additionally, we wait for some gossip from the disconnected replica,
to see that it doesn't mess things up.

unrelated: fix a typo when trying to exhaust the backlog, one that
didn't have any harmful implications

Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
This commit is contained in:
Oran Agra 2021-11-04 08:44:18 +02:00 committed by GitHub
parent f27083a4a8
commit d04f306931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,6 +25,16 @@ proc is_replica_online {info_repl} {
return $result return $result
} }
proc get_last_pong_time {node_id target_cid} {
foreach item [split [R $node_id cluster nodes] \n] {
set args [split $item " "]
if {[lindex $args 0] eq $target_cid} {
return [lindex $args 5]
}
}
fail "Target node ID was not present"
}
set master_id 0 set master_id 0
test "Fill up primary with data" { test "Fill up primary with data" {
@ -74,7 +84,7 @@ test "Replica in loading state is hidden" {
for {set j 0} {$j < $num} {incr j} { for {set j 0} {$j < $num} {incr j} {
set key "{0}" set key "{0}"
append key $j append key $j
R $master_id set key $value R $master_id set $key $value
} }
R $master_id exec R $master_id exec
@ -109,10 +119,28 @@ test "Replica in loading state is hidden" {
} }
test "Check disconnected replica not hidden from slots" { test "Check disconnected replica not hidden from slots" {
# We want to disconnect the replica, but keep it alive so it can still gossip
# Make sure that the replica will not be able to re-connect to the master
R $master_id config set requirepass asdf
# Disconnect replica from primary # Disconnect replica from primary
R $master_id client kill type replica R $master_id client kill type replica
# Check master to have no replicas # Check master to have no replicas
assert {[s $master_id connected_slaves] == 0} assert {[s $master_id connected_slaves] == 0}
set replica_cid [R $replica_id cluster myid]
set initial_pong [get_last_pong_time $master_id $replica_cid]
wait_for_condition 50 100 {
$initial_pong != [get_last_pong_time $master_id $replica_cid]
} else {
fail "Primary never received gossip from replica"
}
# Check that replica is still in the cluster slots # Check that replica is still in the cluster slots
assert {[is_in_slots $master_id $replica]} assert {[is_in_slots $master_id $replica]}
# undo config
R $master_id config set requirepass ""
} }