2
0

replication.tcl 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. start_server {tags {"repl"}} {
  2. start_server {} {
  3. test {First server should have role slave after SLAVEOF} {
  4. r -1 slaveof [srv 0 host] [srv 0 port]
  5. after 1000
  6. s -1 role
  7. } {slave}
  8. test {BRPOPLPUSH replication, when blocking against empty list} {
  9. set rd [redis_deferring_client]
  10. $rd brpoplpush a b 5
  11. r lpush a foo
  12. after 1000
  13. assert_equal [r debug digest] [r -1 debug digest]
  14. }
  15. test {BRPOPLPUSH replication, list exists} {
  16. set rd [redis_deferring_client]
  17. r lpush c 1
  18. r lpush c 2
  19. r lpush c 3
  20. $rd brpoplpush c d 5
  21. after 1000
  22. assert_equal [r debug digest] [r -1 debug digest]
  23. }
  24. test {MASTER and SLAVE dataset should be identical after complex ops} {
  25. createComplexDataset r 10000
  26. after 500
  27. if {[r debug digest] ne [r -1 debug digest]} {
  28. set csv1 [csvdump r]
  29. set csv2 [csvdump {r -1}]
  30. set fd [open /tmp/repldump1.txt w]
  31. puts -nonewline $fd $csv1
  32. close $fd
  33. set fd [open /tmp/repldump2.txt w]
  34. puts -nonewline $fd $csv2
  35. close $fd
  36. puts "Master - Slave inconsistency"
  37. puts "Run diff -u against /tmp/repldump*.txt for more info"
  38. }
  39. assert_equal [r debug digest] [r -1 debug digest]
  40. }
  41. test {MASTER and SLAVE consistency with expire} {
  42. createComplexDataset r 50000 useexpire
  43. after 4000 ;# Make sure everything expired before taking the digest
  44. r keys * ;# Force DEL syntesizing to slave
  45. after 1000 ;# Wait another second. Now everything should be fine.
  46. if {[r debug digest] ne [r -1 debug digest]} {
  47. set csv1 [csvdump r]
  48. set csv2 [csvdump {r -1}]
  49. set fd [open /tmp/repldump1.txt w]
  50. puts -nonewline $fd $csv1
  51. close $fd
  52. set fd [open /tmp/repldump2.txt w]
  53. puts -nonewline $fd $csv2
  54. close $fd
  55. puts "Master - Slave inconsistency"
  56. puts "Run diff -u against /tmp/repldump*.txt for more info"
  57. }
  58. assert_equal [r debug digest] [r -1 debug digest]
  59. }
  60. }
  61. }
  62. start_server {tags {"repl"}} {
  63. r set mykey foo
  64. start_server {} {
  65. test {Second server should have role master at first} {
  66. s role
  67. } {master}
  68. test {SLAVEOF should start with link status "down"} {
  69. r slaveof [srv -1 host] [srv -1 port]
  70. s master_link_status
  71. } {down}
  72. test {The role should immediately be changed to "slave"} {
  73. s role
  74. } {slave}
  75. wait_for_sync r
  76. test {Sync should have transferred keys from master} {
  77. r get mykey
  78. } {foo}
  79. test {The link status should be up} {
  80. s master_link_status
  81. } {up}
  82. test {SET on the master should immediately propagate} {
  83. r -1 set mykey bar
  84. r 0 get mykey
  85. } {bar}
  86. }
  87. }