]> git.saurik.com Git - redis.git/commitdiff
Regression test for the main problem causing issue #141. Minor changes/fixes/addition...
authorantirez <antirez@gmail.com>
Fri, 6 Jan 2012 16:28:40 +0000 (17:28 +0100)
committerantirez <antirez@gmail.com>
Fri, 6 Jan 2012 16:28:40 +0000 (17:28 +0100)
tests/helpers/gen_write_load.tcl [new file with mode: 0644]
tests/integration/replication.tcl
tests/support/test.tcl
tests/test_helper.tcl

diff --git a/tests/helpers/gen_write_load.tcl b/tests/helpers/gen_write_load.tcl
new file mode 100644 (file)
index 0000000..6d1a345
--- /dev/null
@@ -0,0 +1,15 @@
+source tests/support/redis.tcl
+
+proc gen_write_load {host port seconds} {
+    set start_time [clock seconds]
+    set r [redis $host $port 1]
+    $r select 9
+    while 1 {
+        $r set [expr rand()] [expr rand()]
+        if {[clock seconds]-$start_time > $seconds} {
+            exit 0
+        }
+    }
+}
+
+gen_write_load [lindex $argv 0] [lindex $argv 1] [lindex $argv 2]
index 49408ac06fe072055d962ab0c5a9c8d63b0ad79b..e75801574ef55dacb78dcdf0e6b82a6c87e0f8cc 100644 (file)
@@ -65,3 +65,71 @@ start_server {tags {"repl"}} {
         } {0 0}
     }
 }
+
+proc start_write_load {host port seconds} {
+    exec tclsh8.5 tests/helpers/gen_write_load.tcl $host $port $seconds &
+}
+
+proc stop_write_load {handle} {
+    catch {exec /bin/kill -9 $handle}
+}
+
+start_server {tags {"repl"}} {
+    set master [srv 0 client]
+    set master_host [srv 0 host]
+    set master_port [srv 0 port]
+    set slaves {}
+    set load_handle0 [start_write_load $master_host $master_port 20]
+    set load_handle1 [start_write_load $master_host $master_port 20]
+    set load_handle2 [start_write_load $master_host $master_port 20]
+    set load_handle3 [start_write_load $master_host $master_port 20]
+    set load_handle4 [start_write_load $master_host $master_port 20]
+    after 2000
+    start_server {} {
+        lappend slaves [srv 0 client]
+        start_server {} {
+            lappend slaves [srv 0 client]
+            start_server {} {
+                lappend slaves [srv 0 client]
+                test "Connect multiple slaves at the same time (issue #141)" {
+                    [lindex $slaves 0] slaveof $master_host $master_port
+                    [lindex $slaves 1] slaveof $master_host $master_port
+                    [lindex $slaves 2] slaveof $master_host $master_port
+
+                    # Wait for all the three slaves to reach the "online" state
+                    set retry 100
+                    while {$retry} {
+                        set info [r -3 info]
+                        if {[string match {*slave0:*,online*slave1:*,online*slave2:*,online*} $info]} {
+                            break
+                        } else {
+                            incr retry -1
+                            after 100
+                        }
+                    }
+                    if {$retry == 0} {
+                        error "assertion:Slaves not correctly synchronized"
+                    }
+                    stop_write_load $load_handle0
+                    stop_write_load $load_handle1
+                    stop_write_load $load_handle2
+                    stop_write_load $load_handle3
+                    stop_write_load $load_handle4
+                    after 1000
+                    set digest [$master debug digest]
+                    set digest0 [[lindex $slaves 0] debug digest]
+                    set digest1 [[lindex $slaves 1] debug digest]
+                    set digest2 [[lindex $slaves 2] debug digest]
+                    assert {$digest ne 0000000000000000000000000000000000000000}
+                    assert {$digest eq $digest0}
+                    assert {$digest eq $digest1}
+                    assert {$digest eq $digest2}
+                    #puts [$master dbsize]
+                    #puts [[lindex $slaves 0] dbsize]
+                    #puts [[lindex $slaves 1] dbsize]
+                    #puts [[lindex $slaves 2] dbsize]
+                }
+           }
+        }
+    }
+}
index e53d497bb3d79c35ac86fb771266a82bda7b20fd..f66e54b87cfe96b6d584aebb837d1d01e1178096 100644 (file)
@@ -4,7 +4,7 @@ set ::num_failed 0
 set ::tests_failed {}
 
 proc assert {condition} {
-    if {![uplevel 1 expr $condition]} {
+    if {![uplevel 1 [list expr $condition]]} {
         error "assertion:Expected condition '$condition' to be true ([uplevel 1 [list subst -nocommands $condition]])"
     }
 }
index 41c3557dc2748445f6e456f41da86823cd176c05..13b59b92c96c31a6bc63d38d0efe2bf512d80f4a 100644 (file)
@@ -115,7 +115,7 @@ proc reconnect {args} {
     }
 
     # re-set $srv in the servers list
-    set ::servers [lreplace $::servers end+$level 1 $srv]
+    lset ::servers end+$level $srv
 }
 
 proc redis_deferring_client {args} {