diff --git a/tests/cluster/tests/14-consistency-check.tcl b/tests/cluster/tests/14-consistency-check.tcl index 9e0fa5409..e6f7723fc 100644 --- a/tests/cluster/tests/14-consistency-check.tcl +++ b/tests/cluster/tests/14-consistency-check.tcl @@ -32,6 +32,13 @@ proc get_one_of_my_replica {id} { } set replica_port [lindex [lindex [lindex [R $id role] 2] 0] 1] set replica_id_num [get_instance_id_by_port redis $replica_port] + + # To avoid -LOADING reply, wait until replica syncs with master. + wait_for_condition 1000 50 { + [RI $replica_id_num master_link_status] eq {up} + } else { + fail "Replica did not sync in time." + } return $replica_id_num } @@ -105,8 +112,15 @@ proc test_slave_load_expired_keys {aof} { # start the replica again (loading an RDB or AOF file) restart_instance redis $replica_id + # Replica may start a full sync after restart, trying in a loop to avoid + # -LOADING reply in that case. + wait_for_condition 1000 50 { + [catch {set replica_dbsize_3 [R $replica_id dbsize]} e] == 0 + } else { + fail "Replica is not up." + } + # make sure the keys are still there - set replica_dbsize_3 [R $replica_id dbsize] assert {$replica_dbsize_3 > $replica_dbsize_0} # restore settings diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index a452fb22b..edc03f4aa 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -2069,6 +2069,14 @@ start_server {tags {"scripting"}} { } 1 x r replicaof [srv -1 host] [srv -1 port] + + # To avoid -LOADING reply, wait until replica syncs with master. + wait_for_condition 50 100 { + [s master_link_status] eq {up} + } else { + fail "Replica did not sync in time." + } + assert_error {EXECABORT Transaction discarded because of: READONLY *} {$rr exec} assert_error {READONLY You can't write against a read only replica. script: *} {$rr2 exec} $rr close