1
0

psync2-reg.tcl 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 external:skip"}} {
  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. set R_unixsocket($j) [srv [expr 0-$j] unixsocket]
  18. if {$debug_msg} {puts "Log file: [srv [expr 0-$j] stdout]"}
  19. }
  20. # Setup the replication and backlog parameters
  21. test "PSYNC2 #3899 regression: setup" {
  22. $R(1) slaveof $R_host(0) $R_port(0)
  23. $R(2) slaveof $R_host(0) $R_port(0)
  24. $R(0) set foo bar
  25. wait_for_condition 50 1000 {
  26. [status $R(1) master_link_status] == "up" &&
  27. [status $R(2) master_link_status] == "up" &&
  28. [$R(1) dbsize] == 1 &&
  29. [$R(2) dbsize] == 1
  30. } else {
  31. fail "Replicas not replicating from master"
  32. }
  33. $R(0) config set repl-backlog-size 10mb
  34. $R(1) config set repl-backlog-size 10mb
  35. }
  36. set cycle_start_time [clock milliseconds]
  37. set bench_pid [exec src/redis-benchmark -s $R_unixsocket(0) -n 10000000 -r 1000 incr __rand_int__ > /dev/null &]
  38. while 1 {
  39. set elapsed [expr {[clock milliseconds]-$cycle_start_time}]
  40. if {$elapsed > $duration*1000} break
  41. if {rand() < .05} {
  42. test "PSYNC2 #3899 regression: kill first replica" {
  43. $R(1) client kill type master
  44. }
  45. }
  46. if {rand() < .05} {
  47. test "PSYNC2 #3899 regression: kill chained replica" {
  48. $R(2) client kill type master
  49. }
  50. }
  51. after 100
  52. }
  53. exec kill -9 $bench_pid
  54. if {$debug_msg} {
  55. for {set j 0} {$j < 100} {incr j} {
  56. if {
  57. [$R(0) debug digest] == [$R(1) debug digest] &&
  58. [$R(1) debug digest] == [$R(2) debug digest]
  59. } break
  60. puts [$R(0) debug digest]
  61. puts [$R(1) debug digest]
  62. puts [$R(2) debug digest]
  63. after 1000
  64. }
  65. }
  66. test "PSYNC2 #3899 regression: verify consistency" {
  67. wait_for_condition 50 1000 {
  68. ([$R(0) debug digest] eq [$R(1) debug digest]) &&
  69. ([$R(1) debug digest] eq [$R(2) debug digest])
  70. } else {
  71. fail "The three instances have different data sets"
  72. }
  73. }
  74. }}}