"Fossies" - the Fresh Open Source Software Archive

Member "redis-6.0.8/tests/unit/moduleapi/testrdb.tcl" (10 Sep 2020, 5455 Bytes) of package /linux/misc/redis-6.0.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Tcl/Tk source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "testrdb.tcl": 6.0.7_vs_6.0.8.

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