block-repl.tcl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Test replication of blocking lists and zset operations.
  2. # Unlike stream operations such operations are "pop" style, so they consume
  3. # the list or sorted set, and must be replicated correctly.
  4. proc start_bg_block_op {host port db ops} {
  5. set tclsh [info nameofexecutable]
  6. exec $tclsh tests/helpers/bg_block_op.tcl $host $port $db $ops &
  7. }
  8. proc stop_bg_block_op {handle} {
  9. catch {exec /bin/kill -9 $handle}
  10. }
  11. start_server {tags {"repl"}} {
  12. start_server {} {
  13. set master [srv -1 client]
  14. set master_host [srv -1 host]
  15. set master_port [srv -1 port]
  16. set slave [srv 0 client]
  17. set load_handle0 [start_bg_block_op $master_host $master_port 9 100000]
  18. set load_handle1 [start_bg_block_op $master_host $master_port 9 100000]
  19. set load_handle2 [start_bg_block_op $master_host $master_port 9 100000]
  20. test {First server should have role slave after SLAVEOF} {
  21. $slave slaveof $master_host $master_port
  22. after 1000
  23. s 0 role
  24. } {slave}
  25. test {Test replication with blocking lists and sorted sets operations} {
  26. after 25000
  27. stop_bg_block_op $load_handle0
  28. stop_bg_block_op $load_handle1
  29. stop_bg_block_op $load_handle2
  30. set retry 10
  31. while {$retry && ([$master debug digest] ne [$slave debug digest])}\
  32. {
  33. after 1000
  34. incr retry -1
  35. }
  36. if {[$master debug digest] ne [$slave debug digest]} {
  37. set csv1 [csvdump r]
  38. set csv2 [csvdump {r -1}]
  39. set fd [open /tmp/repldump1.txt w]
  40. puts -nonewline $fd $csv1
  41. close $fd
  42. set fd [open /tmp/repldump2.txt w]
  43. puts -nonewline $fd $csv2
  44. close $fd
  45. puts "Master - Slave inconsistency"
  46. puts "Run diff -u against /tmp/repldump*.txt for more info"
  47. }
  48. assert_equal [r debug digest] [r -1 debug digest]
  49. }
  50. }
  51. }