1
0

07-replica-migration.tcl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # Replica migration test.
  2. # Check that orphaned masters are joined by replicas of masters having
  3. # multiple replicas attached, according to the migration barrier settings.
  4. source "../tests/includes/init-tests.tcl"
  5. # Create a cluster with 5 master and 10 slaves, so that we have 2
  6. # slaves for each master.
  7. test "Create a 5 nodes cluster" {
  8. create_cluster 5 10
  9. }
  10. test "Cluster is up" {
  11. assert_cluster_state ok
  12. }
  13. test "Each master should have two replicas attached" {
  14. foreach_redis_id id {
  15. if {$id < 5} {
  16. wait_for_condition 1000 50 {
  17. [llength [lindex [R 0 role] 2]] == 2
  18. } else {
  19. fail "Master #$id does not have 2 slaves as expected"
  20. }
  21. }
  22. }
  23. }
  24. test "Killing all the slaves of master #0 and #1" {
  25. kill_instance redis 5
  26. kill_instance redis 10
  27. kill_instance redis 6
  28. kill_instance redis 11
  29. after 4000
  30. }
  31. foreach_redis_id id {
  32. if {$id < 5} {
  33. test "Master #$id should have at least one replica" {
  34. wait_for_condition 1000 50 {
  35. [llength [lindex [R $id role] 2]] >= 1
  36. } else {
  37. fail "Master #$id has no replicas"
  38. }
  39. }
  40. }
  41. }
  42. # Now test the migration to a master which used to be a slave, after
  43. # a failver.
  44. source "../tests/includes/init-tests.tcl"
  45. # Create a cluster with 5 master and 10 slaves, so that we have 2
  46. # slaves for each master.
  47. test "Create a 5 nodes cluster" {
  48. create_cluster 5 10
  49. }
  50. test "Cluster is up" {
  51. assert_cluster_state ok
  52. }
  53. test "Kill slave #7 of master #2. Only slave left is #12 now" {
  54. kill_instance redis 7
  55. }
  56. set current_epoch [CI 1 cluster_current_epoch]
  57. test "Killing master node #2, #12 should failover" {
  58. kill_instance redis 2
  59. }
  60. test "Wait for failover" {
  61. wait_for_condition 1000 50 {
  62. [CI 1 cluster_current_epoch] > $current_epoch
  63. } else {
  64. fail "No failover detected"
  65. }
  66. }
  67. test "Cluster should eventually be up again" {
  68. assert_cluster_state ok
  69. }
  70. test "Cluster is writable" {
  71. cluster_write_test 1
  72. }
  73. test "Instance 12 is now a master without slaves" {
  74. assert {[RI 12 role] eq {master}}
  75. }
  76. # The remaining instance is now without slaves. Some other slave
  77. # should migrate to it.
  78. test "Master #12 should get at least one migrated replica" {
  79. wait_for_condition 1000 50 {
  80. [llength [lindex [R 12 role] 2]] >= 1
  81. } else {
  82. fail "Master #12 has no replicas"
  83. }
  84. }