]> git.saurik.com Git - redis.git/commitdiff
initial rough integration test for replication
authorPieter Noordhuis <pcnoordhuis@gmail.com>
Fri, 14 May 2010 18:50:58 +0000 (20:50 +0200)
committerPieter Noordhuis <pcnoordhuis@gmail.com>
Fri, 14 May 2010 18:50:58 +0000 (20:50 +0200)
tests/integration/replication.tcl [new file with mode: 0644]
tests/support/util.tcl
tests/test_helper.tcl

diff --git a/tests/integration/replication.tcl b/tests/integration/replication.tcl
new file mode 100644 (file)
index 0000000..6a97edf
--- /dev/null
@@ -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}
+    }
+}
index a084df90c2106c60a59763a69fece6349addae9b..8a7c3f1d81f86d6eeb6bf97c0fe73a5e1688ea2f 100644 (file)
@@ -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)}
 }
index 49dfb16388b0630470cff676c24a3cba88312384..f9830e853fdff66d494ca430664afd0fb601ae9c 100644 (file)
@@ -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} {