propagate.tcl 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. set testmodule [file normalize tests/modules/propagate.so]
  2. tags "modules" {
  3. test {Modules can propagate in async and threaded contexts} {
  4. start_server [list overrides [list loadmodule "$testmodule"]] {
  5. set replica [srv 0 client]
  6. set replica_host [srv 0 host]
  7. set replica_port [srv 0 port]
  8. start_server [list overrides [list loadmodule "$testmodule"]] {
  9. set master [srv 0 client]
  10. set master_host [srv 0 host]
  11. set master_port [srv 0 port]
  12. # Start the replication process...
  13. $replica replicaof $master_host $master_port
  14. wait_for_sync $replica
  15. after 1000
  16. test {module propagates from timer} {
  17. set repl [attach_to_replication_stream]
  18. $master propagate-test.timer
  19. wait_for_condition 5000 10 {
  20. [$replica get timer] eq "3"
  21. } else {
  22. fail "The two counters don't match the expected value."
  23. }
  24. assert_replication_stream $repl {
  25. {select *}
  26. {multi}
  27. {incr timer}
  28. {exec}
  29. {multi}
  30. {incr timer}
  31. {exec}
  32. {multi}
  33. {incr timer}
  34. {exec}
  35. }
  36. close_replication_stream $repl
  37. }
  38. test {module propagates nested ctx case1} {
  39. set repl [attach_to_replication_stream]
  40. $master del timer-nested-start
  41. $master del timer-nested-end
  42. $master propagate-test.timer-nested
  43. wait_for_condition 5000 10 {
  44. [$replica get timer-nested-end] eq "1"
  45. } else {
  46. fail "The two counters don't match the expected value."
  47. }
  48. assert_replication_stream $repl {
  49. {select *}
  50. {multi}
  51. {incrby timer-nested-start 1}
  52. {incrby timer-nested-end 1}
  53. {exec}
  54. }
  55. close_replication_stream $repl
  56. }
  57. test {module propagates nested ctx case2} {
  58. set repl [attach_to_replication_stream]
  59. $master del timer-nested-start
  60. $master del timer-nested-end
  61. $master propagate-test.timer-nested-repl
  62. wait_for_condition 5000 10 {
  63. [$replica get timer-nested-end] eq "1"
  64. } else {
  65. fail "The two counters don't match the expected value."
  66. }
  67. # Note the 'after-call' and 'timer-nested-start' propagation below is out of order (known limitation)
  68. assert_replication_stream $repl {
  69. {select *}
  70. {multi}
  71. {incr using-call}
  72. {incr counter-1}
  73. {incr counter-2}
  74. {incr after-call}
  75. {incr counter-3}
  76. {incr counter-4}
  77. {incrby timer-nested-start 1}
  78. {incrby timer-nested-end 1}
  79. {exec}
  80. }
  81. close_replication_stream $repl
  82. }
  83. test {module propagates from thread} {
  84. set repl [attach_to_replication_stream]
  85. $master propagate-test.thread
  86. wait_for_condition 5000 10 {
  87. [$replica get a-from-thread] eq "3"
  88. } else {
  89. fail "The two counters don't match the expected value."
  90. }
  91. assert_replication_stream $repl {
  92. {select *}
  93. {incr a-from-thread}
  94. {incr b-from-thread}
  95. {incr a-from-thread}
  96. {incr b-from-thread}
  97. {incr a-from-thread}
  98. {incr b-from-thread}
  99. }
  100. close_replication_stream $repl
  101. }
  102. test {module propagates from from command} {
  103. set repl [attach_to_replication_stream]
  104. $master propagate-test.simple
  105. $master propagate-test.mixed
  106. # Note the 'after-call' propagation below is out of order (known limitation)
  107. assert_replication_stream $repl {
  108. {select *}
  109. {multi}
  110. {incr counter-1}
  111. {incr counter-2}
  112. {exec}
  113. {multi}
  114. {incr using-call}
  115. {incr after-call}
  116. {incr counter-1}
  117. {incr counter-2}
  118. {exec}
  119. }
  120. close_replication_stream $repl
  121. }
  122. test {module propagates from from command after good EVAL} {
  123. set repl [attach_to_replication_stream]
  124. assert_equal [ $master eval { return "hello" } 0 ] {hello}
  125. $master propagate-test.simple
  126. $master propagate-test.mixed
  127. # Note the 'after-call' propagation below is out of order (known limitation)
  128. assert_replication_stream $repl {
  129. {select *}
  130. {multi}
  131. {incr counter-1}
  132. {incr counter-2}
  133. {exec}
  134. {multi}
  135. {incr using-call}
  136. {incr after-call}
  137. {incr counter-1}
  138. {incr counter-2}
  139. {exec}
  140. }
  141. close_replication_stream $repl
  142. }
  143. test {module propagates from from command after bad EVAL} {
  144. set repl [attach_to_replication_stream]
  145. catch { $master eval { return "hello" } -12 } e
  146. assert_equal $e {ERR Number of keys can't be negative}
  147. $master propagate-test.simple
  148. $master propagate-test.mixed
  149. # Note the 'after-call' propagation below is out of order (known limitation)
  150. assert_replication_stream $repl {
  151. {select *}
  152. {multi}
  153. {incr counter-1}
  154. {incr counter-2}
  155. {exec}
  156. {multi}
  157. {incr using-call}
  158. {incr after-call}
  159. {incr counter-1}
  160. {incr counter-2}
  161. {exec}
  162. }
  163. close_replication_stream $repl
  164. }
  165. test {module propagates from from multi-exec} {
  166. set repl [attach_to_replication_stream]
  167. $master multi
  168. $master propagate-test.simple
  169. $master propagate-test.mixed
  170. $master exec
  171. wait_for_ofs_sync $master $replica
  172. # Note the 'after-call' propagation below is out of order (known limitation)
  173. assert_replication_stream $repl {
  174. {select *}
  175. {multi}
  176. {incr counter-1}
  177. {incr counter-2}
  178. {incr using-call}
  179. {incr after-call}
  180. {incr counter-1}
  181. {incr counter-2}
  182. {exec}
  183. }
  184. close_replication_stream $repl
  185. }
  186. test {module RM_Call of expired key propagation} {
  187. $master debug set-active-expire 0
  188. $master set k1 900 px 100
  189. wait_for_ofs_sync $master $replica
  190. after 110
  191. set repl [attach_to_replication_stream]
  192. $master propagate-test.incr k1
  193. wait_for_ofs_sync $master $replica
  194. assert_replication_stream $repl {
  195. {select *}
  196. {del k1}
  197. {propagate-test.incr k1}
  198. }
  199. close_replication_stream $repl
  200. assert_equal [$master get k1] 1
  201. assert_equal [$master ttl k1] -1
  202. assert_equal [$replica get k1] 1
  203. assert_equal [$replica ttl k1] -1
  204. }
  205. assert_equal [s -1 unexpected_error_replies] 0
  206. }
  207. }
  208. }
  209. }
  210. tags "modules aof" {
  211. test {Modules RM_Replicate replicates MULTI/EXEC correctly} {
  212. start_server [list overrides [list loadmodule "$testmodule"]] {
  213. # Enable the AOF
  214. r config set appendonly yes
  215. r config set auto-aof-rewrite-percentage 0 ; # Disable auto-rewrite.
  216. waitForBgrewriteaof r
  217. r propagate-test.simple
  218. r propagate-test.mixed
  219. r multi
  220. r propagate-test.simple
  221. r propagate-test.mixed
  222. r exec
  223. # Load the AOF
  224. r debug loadaof
  225. assert_equal [s 0 unexpected_error_replies] 0
  226. }
  227. }
  228. }