1# Issue 3899 regression test. 2# We create a chain of three instances: master -> slave -> slave2 3# and continuously break the link while traffic is generated by 4# redis-benchmark. At the end we check that the data is the same 5# everywhere. 6 7start_server {tags {"psync2"}} { 8start_server {} { 9start_server {} { 10 # Config 11 set debug_msg 0 ; # Enable additional debug messages 12 13 set no_exit 0 ; # Do not exit at end of the test 14 15 set duration 20 ; # Total test seconds 16 17 for {set j 0} {$j < 3} {incr j} { 18 set R($j) [srv [expr 0-$j] client] 19 set R_host($j) [srv [expr 0-$j] host] 20 set R_port($j) [srv [expr 0-$j] port] 21 if {$debug_msg} {puts "Log file: [srv [expr 0-$j] stdout]"} 22 } 23 24 # Setup the replication and backlog parameters 25 test "PSYNC2 #3899 regression: setup" { 26 $R(1) slaveof $R_host(0) $R_port(0) 27 $R(2) slaveof $R_host(0) $R_port(0) 28 $R(0) set foo bar 29 wait_for_condition 50 1000 { 30 [$R(1) dbsize] == 1 && [$R(2) dbsize] == 1 31 } else { 32 fail "Replicas not replicating from master" 33 } 34 $R(0) config set repl-backlog-size 10mb 35 $R(1) config set repl-backlog-size 10mb 36 } 37 38 set cycle_start_time [clock milliseconds] 39 set bench_pid [exec src/redis-benchmark -p $R_port(0) -n 10000000 -r 1000 incr __rand_int__ > /dev/null &] 40 while 1 { 41 set elapsed [expr {[clock milliseconds]-$cycle_start_time}] 42 if {$elapsed > $duration*1000} break 43 if {rand() < .05} { 44 test "PSYNC2 #3899 regression: kill first replica" { 45 $R(1) client kill type master 46 } 47 } 48 if {rand() < .05} { 49 test "PSYNC2 #3899 regression: kill chained replica" { 50 $R(2) client kill type master 51 } 52 } 53 after 100 54 } 55 exec kill -9 $bench_pid 56 57 if {$debug_msg} { 58 for {set j 0} {$j < 100} {incr j} { 59 if { 60 [$R(0) debug digest] == [$R(1) debug digest] && 61 [$R(1) debug digest] == [$R(2) debug digest] 62 } break 63 puts [$R(0) debug digest] 64 puts [$R(1) debug digest] 65 puts [$R(2) debug digest] 66 after 1000 67 } 68 } 69 70 test "PSYNC2 #3899 regression: verify consistency" { 71 wait_for_condition 50 1000 { 72 ([$R(0) debug digest] eq [$R(1) debug digest]) && 73 ([$R(1) debug digest] eq [$R(2) debug digest]) 74 } else { 75 fail "The three instances have different data sets" 76 } 77 } 78}}} 79