2
0

psync2-reg.tcl 2.6 KB

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