psync2-pingoff.tcl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Test the meaningful offset implementation to make sure masters
  2. # are able to PSYNC with replicas even if the replication stream
  3. # has pending PINGs at the end.
  4. start_server {tags {"psync2"}} {
  5. start_server {} {
  6. # Config
  7. set debug_msg 0 ; # Enable additional debug messages
  8. for {set j 0} {$j < 2} {incr j} {
  9. set R($j) [srv [expr 0-$j] client]
  10. set R_host($j) [srv [expr 0-$j] host]
  11. set R_port($j) [srv [expr 0-$j] port]
  12. $R($j) CONFIG SET repl-ping-replica-period 1
  13. if {$debug_msg} {puts "Log file: [srv [expr 0-$j] stdout]"}
  14. }
  15. # Setup replication
  16. test "PSYNC2 meaningful offset: setup" {
  17. $R(1) replicaof $R_host(0) $R_port(0)
  18. $R(0) set foo bar
  19. wait_for_condition 50 1000 {
  20. [$R(0) dbsize] == 1 && [$R(1) dbsize] == 1
  21. } else {
  22. fail "Replicas not replicating from master"
  23. }
  24. }
  25. test "PSYNC2 meaningful offset: write and wait replication" {
  26. $R(0) INCR counter
  27. $R(0) INCR counter
  28. $R(0) INCR counter
  29. wait_for_condition 50 1000 {
  30. [$R(0) GET counter] eq [$R(1) GET counter]
  31. } else {
  32. fail "Master and replica don't agree about counter"
  33. }
  34. }
  35. # In this test we'll make sure the replica will get stuck, but with
  36. # an active connection: this way the master will continue to send PINGs
  37. # every second (we modified the PING period earlier)
  38. test "PSYNC2 meaningful offset: pause replica and promote it" {
  39. $R(1) MULTI
  40. $R(1) DEBUG SLEEP 5
  41. $R(1) SLAVEOF NO ONE
  42. $R(1) EXEC
  43. $R(1) ping ; # Wait for it to return back available
  44. }
  45. test "Make the old master a replica of the new one and check conditions" {
  46. set sync_partial [status $R(1) sync_partial_ok]
  47. assert {$sync_partial == 0}
  48. $R(0) REPLICAOF $R_host(1) $R_port(1)
  49. wait_for_condition 50 1000 {
  50. [status $R(1) sync_partial_ok] == 1
  51. } else {
  52. fail "The new master was not able to partial sync"
  53. }
  54. }
  55. }}