From ba6f40ea94ee4937d0cbb32f822bbfbac6dd4719 Mon Sep 17 00:00:00 2001 From: Oran Agra Date: Sun, 17 May 2020 18:26:02 +0300 Subject: [PATCH] add regression test for the race in #7205 with the original version of 6.0.0, this test detects an excessive full sync. with the fix in 146201c69, this test detects memory corruption, especially when using libc allocator with or without valgrind. --- tests/integration/replication.tcl | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) 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 + } + } + } +}