oom-score-adj.tcl 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. set system_name [string tolower [exec uname -s]]
  2. set user_id [exec id -u]
  3. if {$system_name eq {linux}} {
  4. start_server {tags {"oom-score-adj external:skip"}} {
  5. proc get_oom_score_adj {{pid ""}} {
  6. if {$pid == ""} {
  7. set pid [srv 0 pid]
  8. }
  9. set fd [open "/proc/$pid/oom_score_adj" "r"]
  10. set val [gets $fd]
  11. close $fd
  12. return $val
  13. }
  14. test {CONFIG SET oom-score-adj works as expected} {
  15. set base [get_oom_score_adj]
  16. # Enable oom-score-adj, check defaults
  17. r config set oom-score-adj-values "10 20 30"
  18. r config set oom-score-adj yes
  19. assert {[get_oom_score_adj] == [expr $base + 10]}
  20. # Modify current class
  21. r config set oom-score-adj-values "15 20 30"
  22. assert {[get_oom_score_adj] == [expr $base + 15]}
  23. # Check replica class
  24. r replicaof localhost 1
  25. assert {[get_oom_score_adj] == [expr $base + 20]}
  26. r replicaof no one
  27. assert {[get_oom_score_adj] == [expr $base + 15]}
  28. # Check child process
  29. r set key-a value-a
  30. r config set rdb-key-save-delay 1000000
  31. r bgsave
  32. set child_pid [get_child_pid 0]
  33. # Wait until background child process to setOOMScoreAdj success.
  34. wait_for_condition 100 10 {
  35. [get_oom_score_adj $child_pid] == [expr $base + 30]
  36. } else {
  37. fail "Set oom-score-adj of background child process is not ok"
  38. }
  39. }
  40. # Failed oom-score-adj tests can only run unprivileged
  41. if {$user_id != 0} {
  42. test {CONFIG SET oom-score-adj handles configuration failures} {
  43. # Bad config
  44. r config set oom-score-adj no
  45. r config set oom-score-adj-values "-1000 -1000 -1000"
  46. # Make sure it fails
  47. catch {r config set oom-score-adj yes} e
  48. assert_match {*Failed to set*} $e
  49. # Make sure it remains off
  50. assert {[r config get oom-score-adj] == "oom-score-adj no"}
  51. # Fix config
  52. r config set oom-score-adj-values "0 100 100"
  53. r config set oom-score-adj yes
  54. # Make sure it fails
  55. catch {r config set oom-score-adj-values "-1000 -1000 -1000"} e
  56. assert_match {*Failed*} $e
  57. # Make sure previous values remain
  58. assert {[r config get oom-score-adj-values] == {oom-score-adj-values {0 100 100}}}
  59. }
  60. }
  61. }
  62. }