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 <debing.sun@redis.com>
This commit is contained in:
sundb 2023-12-27 14:42:46 +08:00 committed by GitHub
parent 1aa633d61b
commit bef5715374
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -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
}