2
0

psync2-reg.tcl 2.6 KB

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