summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2020-05-17 17:59:14 +0200
committerGitHub <noreply@github.com>2020-05-17 17:59:14 +0200
commit08d00dad5297440ea0680faf236a03d7390e9e51 (patch)
tree28246e899e9b2802c70aa276993fd004a1b1bd1e
parent624742d9b40d20afe8b694c2dc0b0349f8b7aaad (diff)
parent357aace8953e5c904d9d9d408258cd824df1717c (diff)
downloadredis-08d00dad5297440ea0680faf236a03d7390e9e51.tar.gz
Merge pull request #7264 from oranagra/test_for_7205
add regression test for the race in #7205
-rw-r--r--tests/integration/replication.tcl52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/integration/replication.tcl b/tests/integration/replication.tcl
index 22b0bfeaf..e5079d9dd 100644
--- a/tests/integration/replication.tcl
+++ b/tests/integration/replication.tcl
@@ -637,3 +637,55 @@ start_server {tags {"repl"}} {
}
}
}
+
+test {replicaof right after disconnection} {
+ # this is a rare race condition that was reproduced sporadically by the psync2 unit.
+ # see details in #7205
+ start_server {tags {"repl"}} {
+ set replica1 [srv 0 client]
+ set replica1_host [srv 0 host]
+ set replica1_port [srv 0 port]
+ set replica1_log [srv 0 stdout]
+ start_server {} {
+ set replica2 [srv 0 client]
+ set replica2_host [srv 0 host]
+ set replica2_port [srv 0 port]
+ set replica2_log [srv 0 stdout]
+ start_server {} {
+ set master [srv 0 client]
+ set master_host [srv 0 host]
+ set master_port [srv 0 port]
+ $replica1 replicaof $master_host $master_port
+ $replica2 replicaof $master_host $master_port
+
+ wait_for_condition 50 100 {
+ [string match {*master_link_status:up*} [$replica1 info replication]] &&
+ [string match {*master_link_status:up*} [$replica2 info replication]]
+ } else {
+ fail "Can't turn the instance into a replica"
+ }
+
+ set rd [redis_deferring_client -1]
+ $rd debug sleep 1
+ after 100
+
+ # when replica2 will wake up from the sleep it will find both disconnection
+ # from it's master and also a replicaof command at the same event loop
+ $master client kill type replica
+ $replica2 replicaof $replica1_host $replica1_port
+ $rd read
+
+ wait_for_condition 50 100 {
+ [string match {*master_link_status:up*} [$replica2 info replication]]
+ } else {
+ fail "role change failed."
+ }
+
+ # make sure psync succeeded, and there were no unexpected full syncs.
+ assert_equal [status $master sync_full] 2
+ assert_equal [status $replica1 sync_full] 0
+ assert_equal [status $replica2 sync_full] 0
+ }
+ }
+ }
+}