2
0

testrdb.tcl 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. set testmodule [file normalize tests/modules/testrdb.so]
  2. tags "modules" {
  3. test {modules are able to persist types} {
  4. start_server [list overrides [list loadmodule "$testmodule"]] {
  5. r testrdb.set.key key1 value1
  6. assert_equal "value1" [r testrdb.get.key key1]
  7. r debug reload
  8. assert_equal "value1" [r testrdb.get.key key1]
  9. }
  10. }
  11. test {modules global are lost without aux} {
  12. set server_path [tmpdir "server.module-testrdb"]
  13. start_server [list overrides [list loadmodule "$testmodule" "dir" $server_path]] {
  14. r testrdb.set.before global1
  15. assert_equal "global1" [r testrdb.get.before]
  16. }
  17. start_server [list overrides [list loadmodule "$testmodule" "dir" $server_path]] {
  18. assert_equal "" [r testrdb.get.before]
  19. }
  20. }
  21. test {modules are able to persist globals before and after} {
  22. set server_path [tmpdir "server.module-testrdb"]
  23. start_server [list overrides [list loadmodule "$testmodule 2" "dir" $server_path]] {
  24. r testrdb.set.before global1
  25. r testrdb.set.after global2
  26. assert_equal "global1" [r testrdb.get.before]
  27. assert_equal "global2" [r testrdb.get.after]
  28. }
  29. start_server [list overrides [list loadmodule "$testmodule 2" "dir" $server_path]] {
  30. assert_equal "global1" [r testrdb.get.before]
  31. assert_equal "global2" [r testrdb.get.after]
  32. }
  33. }
  34. test {modules are able to persist globals just after} {
  35. set server_path [tmpdir "server.module-testrdb"]
  36. start_server [list overrides [list loadmodule "$testmodule 1" "dir" $server_path]] {
  37. r testrdb.set.after global2
  38. assert_equal "global2" [r testrdb.get.after]
  39. }
  40. start_server [list overrides [list loadmodule "$testmodule 1" "dir" $server_path]] {
  41. assert_equal "global2" [r testrdb.get.after]
  42. }
  43. }
  44. tags {repl} {
  45. test {diskless loading short read with module} {
  46. start_server [list overrides [list loadmodule "$testmodule"]] {
  47. set replica [srv 0 client]
  48. set replica_host [srv 0 host]
  49. set replica_port [srv 0 port]
  50. start_server [list overrides [list loadmodule "$testmodule"]] {
  51. set master [srv 0 client]
  52. set master_host [srv 0 host]
  53. set master_port [srv 0 port]
  54. # Set master and replica to use diskless replication
  55. $master config set repl-diskless-sync yes
  56. $master config set rdbcompression no
  57. $replica config set repl-diskless-load swapdb
  58. for {set k 0} {$k < 30} {incr k} {
  59. r testrdb.set.key key$k [string repeat A [expr {int(rand()*1000000)}]]
  60. }
  61. # Start the replication process...
  62. set loglines [count_log_lines -1]
  63. $master config set repl-diskless-sync-delay 0
  64. $replica replicaof $master_host $master_port
  65. # kill the replication at various points
  66. set attempts 3
  67. if {$::accurate} { set attempts 10 }
  68. for {set i 0} {$i < $attempts} {incr i} {
  69. # wait for the replica to start reading the rdb
  70. # using the log file since the replica only responds to INFO once in 2mb
  71. wait_for_log_message -1 "*Loading DB in memory*" $loglines 2000 1
  72. # add some additional random sleep so that we kill the master on a different place each time
  73. after [expr {int(rand()*100)}]
  74. # kill the replica connection on the master
  75. set killed [$master client kill type replica]
  76. if {[catch {
  77. set res [wait_for_log_message -1 "*Internal error in RDB*" $loglines 100 10]
  78. if {$::verbose} {
  79. puts $res
  80. }
  81. }]} {
  82. puts "failed triggering short read"
  83. # force the replica to try another full sync
  84. $master client kill type replica
  85. $master set asdf asdf
  86. # the side effect of resizing the backlog is that it is flushed (16k is the min size)
  87. $master config set repl-backlog-size [expr {16384 + $i}]
  88. }
  89. # wait for loading to stop (fail)
  90. set loglines [count_log_lines -1]
  91. wait_for_condition 100 10 {
  92. [s -1 loading] eq 0
  93. } else {
  94. fail "Replica didn't disconnect"
  95. }
  96. }
  97. # enable fast shutdown
  98. $master config set rdb-key-save-delay 0
  99. }
  100. }
  101. }
  102. }
  103. }