"Fossies" - the Fresh Open Source Software Archive

Member "redis-6.0.8/tests/integration/rdb.tcl" (10 Sep 2020, 6636 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 "rdb.tcl": 6.0.7_vs_6.0.8.

    1 set server_path [tmpdir "server.rdb-encoding-test"]
    2 
    3 # Copy RDB with different encodings in server path
    4 exec cp tests/assets/encodings.rdb $server_path
    5 
    6 start_server [list overrides [list "dir" $server_path "dbfilename" "encodings.rdb"]] {
    7   test "RDB encoding loading test" {
    8     r select 0
    9     csvdump r
   10   } {"0","compressible","string","aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
   11 "0","hash","hash","a","1","aa","10","aaa","100","b","2","bb","20","bbb","200","c","3","cc","30","ccc","300","ddd","400","eee","5000000000",
   12 "0","hash_zipped","hash","a","1","b","2","c","3",
   13 "0","list","list","1","2","3","a","b","c","100000","6000000000","1","2","3","a","b","c","100000","6000000000","1","2","3","a","b","c","100000","6000000000",
   14 "0","list_zipped","list","1","2","3","a","b","c","100000","6000000000",
   15 "0","number","string","10"
   16 "0","set","set","1","100000","2","3","6000000000","a","b","c",
   17 "0","set_zipped_1","set","1","2","3","4",
   18 "0","set_zipped_2","set","100000","200000","300000","400000",
   19 "0","set_zipped_3","set","1000000000","2000000000","3000000000","4000000000","5000000000","6000000000",
   20 "0","string","string","Hello World"
   21 "0","zset","zset","a","1","b","2","c","3","aa","10","bb","20","cc","30","aaa","100","bbb","200","ccc","300","aaaa","1000","cccc","123456789","bbbb","5000000000",
   22 "0","zset_zipped","zset","a","1","b","2","c","3",
   23 }
   24 }
   25 
   26 set server_path [tmpdir "server.rdb-startup-test"]
   27 
   28 start_server [list overrides [list "dir" $server_path] keep_persistence true] {
   29     test {Server started empty with non-existing RDB file} {
   30         r debug digest
   31     } {0000000000000000000000000000000000000000}
   32     # Save an RDB file, needed for the next test.
   33     r save
   34 }
   35 
   36 start_server [list overrides [list "dir" $server_path] keep_persistence true] {
   37     test {Server started empty with empty RDB file} {
   38         r debug digest
   39     } {0000000000000000000000000000000000000000}
   40 }
   41 
   42 start_server [list overrides [list "dir" $server_path] keep_persistence true] {
   43     test {Test RDB stream encoding} {
   44         for {set j 0} {$j < 1000} {incr j} {
   45             if {rand() < 0.9} {
   46                 r xadd stream * foo $j
   47             } else {
   48                 r xadd stream * bar $j
   49             }
   50         }
   51         r xgroup create stream mygroup 0
   52         r xreadgroup GROUP mygroup Alice COUNT 1 STREAMS stream >
   53         set digest [r debug digest]
   54         r debug reload
   55         set newdigest [r debug digest]
   56         assert {$digest eq $newdigest}
   57         r del stream
   58     }
   59 }
   60 
   61 # Helper function to start a server and kill it, just to check the error
   62 # logged.
   63 set defaults {}
   64 proc start_server_and_kill_it {overrides code} {
   65     upvar defaults defaults srv srv server_path server_path
   66     set config [concat $defaults $overrides]
   67     set srv [start_server [list overrides $config keep_persistence true]]
   68     uplevel 1 $code
   69     kill_server $srv
   70 }
   71 
   72 # Make the RDB file unreadable
   73 file attributes [file join $server_path dump.rdb] -permissions 0222
   74 
   75 # Detect root account (it is able to read the file even with 002 perm)
   76 set isroot 0
   77 catch {
   78     open [file join $server_path dump.rdb]
   79     set isroot 1
   80 }
   81 
   82 # Now make sure the server aborted with an error
   83 if {!$isroot} {
   84     start_server_and_kill_it [list "dir" $server_path] {
   85         test {Server should not start if RDB file can't be open} {
   86             wait_for_condition 50 100 {
   87                 [string match {*Fatal error loading*} \
   88                     [exec tail -1 < [dict get $srv stdout]]]
   89             } else {
   90                 fail "Server started even if RDB was unreadable!"
   91             }
   92         }
   93     }
   94 }
   95 
   96 # Fix permissions of the RDB file.
   97 file attributes [file join $server_path dump.rdb] -permissions 0666
   98 
   99 # Corrupt its CRC64 checksum.
  100 set filesize [file size [file join $server_path dump.rdb]]
  101 set fd [open [file join $server_path dump.rdb] r+]
  102 fconfigure $fd -translation binary
  103 seek $fd -8 end
  104 puts -nonewline $fd "foobar00"; # Corrupt the checksum
  105 close $fd
  106 
  107 # Now make sure the server aborted with an error
  108 start_server_and_kill_it [list "dir" $server_path] {
  109     test {Server should not start if RDB is corrupted} {
  110         wait_for_condition 50 100 {
  111             [string match {*CRC error*} \
  112                 [exec tail -10 < [dict get $srv stdout]]]
  113         } else {
  114             fail "Server started even if RDB was corrupted!"
  115         }
  116     }
  117 }
  118 
  119 start_server {} {
  120     test {Test FLUSHALL aborts bgsave} {
  121         # 1000 keys with 1ms sleep per key shuld take 1 second
  122         r config set rdb-key-save-delay 1000
  123         r debug populate 1000
  124         r bgsave
  125         assert_equal [s rdb_bgsave_in_progress] 1
  126         r flushall
  127         # wait half a second max
  128         wait_for_condition 5 100 {
  129             [s rdb_bgsave_in_progress] == 0
  130         } else {
  131             fail "bgsave not aborted"
  132         }
  133         # veirfy that bgsave failed, by checking that the change counter is still high
  134         assert_lessthan 999 [s rdb_changes_since_last_save]
  135         # make sure the server is still writable
  136         r set x xx
  137     }
  138 
  139     test {bgsave resets the change counter} {
  140         r config set rdb-key-save-delay 0
  141         r bgsave
  142         wait_for_condition 50 100 {
  143             [s rdb_bgsave_in_progress] == 0
  144         } else {
  145             fail "bgsave not done"
  146         }
  147         assert_equal [s rdb_changes_since_last_save] 0
  148     }
  149 }
  150 
  151 test {client freed during loading} {
  152     start_server [list overrides [list key-load-delay 10 rdbcompression no]] {
  153         # create a big rdb that will take long to load. it is important
  154         # for keys to be big since the server processes events only once in 2mb.
  155         # 100mb of rdb, 100k keys will load in more than 1 second
  156         r debug populate 100000 key 1000
  157 
  158         restart_server 0 false
  159 
  160         # make sure it's still loading
  161         assert_equal [s loading] 1
  162 
  163         # connect and disconnect 10 clients
  164         set clients {}
  165         for {set j 0} {$j < 10} {incr j} {
  166             lappend clients [redis_deferring_client]
  167         }
  168         foreach rd $clients {
  169             $rd debug log bla
  170         }
  171         foreach rd $clients {
  172             $rd read
  173         }
  174         foreach rd $clients {
  175             $rd close
  176         }
  177 
  178         # make sure the server freed the clients
  179         wait_for_condition 100 100 {
  180             [s connected_clients] < 3
  181         } else {
  182             fail "clients didn't disconnect"
  183         }
  184 
  185         # make sure it's still loading
  186         assert_equal [s loading] 1
  187 
  188         # no need to keep waiting for loading to complete
  189         exec kill [srv 0 pid]
  190     }
  191 }