testrdb.tcl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. $master config set repl-diskless-sync-delay 0
  63. $replica replicaof $master_host $master_port
  64. # kill the replication at various points
  65. set attempts 3
  66. if {$::accurate} { set attempts 10 }
  67. for {set i 0} {$i < $attempts} {incr i} {
  68. # wait for the replica to start reading the rdb
  69. # using the log file since the replica only responds to INFO once in 2mb
  70. wait_for_log_message -1 "*Loading DB in memory*" 5 2000 1
  71. # add some additional random sleep so that we kill the master on a different place each time
  72. after [expr {int(rand()*100)}]
  73. # kill the replica connection on the master
  74. set killed [$master client kill type replica]
  75. if {[catch {
  76. set res [wait_for_log_message -1 "*Internal error in RDB*" 5 100 10]
  77. if {$::verbose} {
  78. puts $res
  79. }
  80. }]} {
  81. puts "failed triggering short read"
  82. # force the replica to try another full sync
  83. $master client kill type replica
  84. $master set asdf asdf
  85. # the side effect of resizing the backlog is that it is flushed (16k is the min size)
  86. $master config set repl-backlog-size [expr {16384 + $i}]
  87. }
  88. # wait for loading to stop (fail)
  89. wait_for_condition 100 10 {
  90. [s -1 loading] eq 0
  91. } else {
  92. fail "Replica didn't disconnect"
  93. }
  94. }
  95. # enable fast shutdown
  96. $master config set rdb-key-save-delay 0
  97. }
  98. }
  99. }
  100. }
  101. }