From 85ecc65edcdb08519a8cf1cd05b9eb910c26eb5c Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Fri, 14 May 2010 20:50:58 +0200 Subject: [PATCH] initial rough integration test for replication --- tests/integration/replication.tcl | 32 +++++++++++++++++++++++++++++++ tests/support/util.tcl | 10 ++++++++++ tests/test_helper.tcl | 1 + 3 files changed, 43 insertions(+) create mode 100644 tests/integration/replication.tcl diff --git a/tests/integration/replication.tcl b/tests/integration/replication.tcl new file mode 100644 index 00000000..6a97edf4 --- /dev/null +++ b/tests/integration/replication.tcl @@ -0,0 +1,32 @@ +start_server default.conf {} { + r set mykey foo + + start_server default.conf {} { + test {Second server should have role master at first} { + s role + } {master} + + test {SLAVEOF should start with link status "down"} { + r slaveof [srv -1 host] [srv -1 port] + s master_link_status + } {down} + + test {The role should immediately be changed to "slave"} { + s role + } {slave} + + wait_for_sync r + test {Sync should have transferred keys from master} { + r get mykey + } {foo} + + test {The link status should be up} { + s master_link_status + } {up} + + test {SET on the master should immediately propagate} { + r -1 set mykey bar + r 0 get mykey + } {bar} + } +} diff --git a/tests/support/util.tcl b/tests/support/util.tcl index a084df90..8a7c3f1d 100644 --- a/tests/support/util.tcl +++ b/tests/support/util.tcl @@ -56,6 +56,16 @@ proc waitForBgrewriteaof r { } } +proc wait_for_sync r { + while 1 { + if {[status r master_link_status] eq "down"} { + after 10 + } else { + break + } + } +} + proc randomInt {max} { expr {int(rand()*$max)} } diff --git a/tests/test_helper.tcl b/tests/test_helper.tcl index 49dfb163..f9830e85 100644 --- a/tests/test_helper.tcl +++ b/tests/test_helper.tcl @@ -60,6 +60,7 @@ proc main {} { execute_tests "unit/sort" execute_tests "unit/expire" execute_tests "unit/other" + execute_tests "integration/replication" puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed" if {$::failed > 0} { -- 2.47.2