"Fossies" - the Fresh Open Source Software Archive

Member "redis-6.0.8/tests/unit/oom-score-adj.tcl" (10 Sep 2020, 2448 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 "oom-score-adj.tcl": 6.0.7_vs_6.0.8.

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