1
0

shutdown.tcl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. start_server {tags {"shutdown external:skip"}} {
  2. test {Temp rdb will be deleted if we use bg_unlink when shutdown} {
  3. for {set i 0} {$i < 20} {incr i} {
  4. r set $i $i
  5. }
  6. # It will cost 2s(20 * 100ms) to dump rdb
  7. r config set rdb-key-save-delay 100000
  8. # Child is dumping rdb
  9. r bgsave
  10. after 100
  11. set dir [lindex [r config get dir] 1]
  12. set child_pid [get_child_pid 0]
  13. set temp_rdb [file join [lindex [r config get dir] 1] temp-${child_pid}.rdb]
  14. # Temp rdb must be existed
  15. assert {[file exists $temp_rdb]}
  16. catch {r shutdown nosave}
  17. # Make sure the server was killed
  18. catch {set rd [redis_deferring_client]} e
  19. assert_match {*connection refused*} $e
  20. # Temp rdb file must be deleted
  21. assert {![file exists $temp_rdb]}
  22. }
  23. }
  24. start_server {tags {"shutdown external:skip"}} {
  25. test {Temp rdb will be deleted in signal handle} {
  26. for {set i 0} {$i < 20} {incr i} {
  27. r set $i $i
  28. }
  29. # It will cost 2s (20 * 100ms) to dump rdb
  30. r config set rdb-key-save-delay 100000
  31. set pid [s process_id]
  32. set temp_rdb [file join [lindex [r config get dir] 1] temp-${pid}.rdb]
  33. # trigger a shutdown which will save an rdb
  34. exec kill -SIGINT $pid
  35. # Wait for creation of temp rdb
  36. wait_for_condition 50 10 {
  37. [file exists $temp_rdb]
  38. } else {
  39. fail "Can't trigger rdb save on shutdown"
  40. }
  41. # Insist on immediate shutdown, temp rdb file must be deleted
  42. exec kill -SIGINT $pid
  43. # wait for the rdb file to be deleted
  44. wait_for_condition 50 10 {
  45. ![file exists $temp_rdb]
  46. } else {
  47. fail "Can't trigger rdb save on shutdown"
  48. }
  49. }
  50. }