From 9706ca64042c8f59c60fc2887872b5f061479f10 Mon Sep 17 00:00:00 2001 From: sundb Date: Wed, 27 Dec 2023 14:42:46 +0800 Subject: [PATCH] Fix oom-score-adj test due to no permission (#12887) Fix #12792 On ubuntu 23(lunar), non-root users will not be allowed to change the oom_score_adj of a process to a value that is too low. Since terminal's default oom_score_adj is 200, if we run the test on terminal, we won't be able to set the oom_score_adj of the redis process to 9 or 22, which is too low. Reproduction on ubuntu 23(lunar) terminal: ```sh $ cat /proc/`pgrep redis-server`/oom_score_adj 200 $ echo 100 > /proc/`pgrep redis-server`/oom_score_adj # success without error $ echo 99 > /proc/`pgrep redis-server`/oom_score_adj echo: write error: Permission denied ``` As from the output above, we can only set the minimum oom score of redis processes to 100. By modifying the test, make oom_score_adj only increase upwards and not decrease. --------- Co-authored-by: debing.sun --- tests/unit/oom-score-adj.tcl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/unit/oom-score-adj.tcl b/tests/unit/oom-score-adj.tcl index 6c7b71392..c557fee42 100644 --- a/tests/unit/oom-score-adj.tcl +++ b/tests/unit/oom-score-adj.tcl @@ -101,25 +101,27 @@ if {$system_name eq {linux}} { test {CONFIG SET oom score restored on disable} { r config set oom-score-adj no - set_oom_score_adj 22 - assert_equal [get_oom_score_adj] 22 + set custom_oom [expr [get_oom_score_adj] + 1] + set_oom_score_adj $custom_oom + assert_equal [get_oom_score_adj] $custom_oom r config set oom-score-adj-values "9 9 9" oom-score-adj yes - assert_equal [get_oom_score_adj] [expr 9+22] + assert_equal [get_oom_score_adj] [expr 9+$custom_oom] r config set oom-score-adj no - assert_equal [get_oom_score_adj] 22 + assert_equal [get_oom_score_adj] $custom_oom } test {CONFIG SET oom score relative and absolute} { - set custom_oom 9 r config set oom-score-adj no set base_oom [get_oom_score_adj] + set custom_oom 9 r config set oom-score-adj-values "$custom_oom $custom_oom $custom_oom" oom-score-adj relative assert_equal [get_oom_score_adj] [expr $base_oom+$custom_oom] - r config set oom-score-adj absolute + set custom_oom [expr [get_oom_score_adj] + 1] + r config set oom-score-adj-values "$custom_oom $custom_oom $custom_oom" oom-score-adj absolute assert_equal [get_oom_score_adj] $custom_oom }