Merge pull request #5321 from thaJeztah/fix_oom_score_test

fix TestSetOOMScoreBoundaries and replace missing busybox image in CI
This commit is contained in:
Michael Crosby 2021-04-08 14:54:50 -04:00 committed by GitHub
commit ceb08756a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

View File

@ -32,7 +32,7 @@ const (
)
var (
testImage = "mirror.gcr.io/library/busybox:latest"
testImage = "mirror.gcr.io/library/busybox:1.32.0"
shortCommand = withProcessArgs("true")
longCommand = withProcessArgs("/bin/sh", "-c", "while true; do sleep 1; done")
)

View File

@ -65,7 +65,8 @@ func SetOOMScore(pid, score int) error {
return nil
}
// GetOOMScoreAdj gets the oom score for a process
// GetOOMScoreAdj gets the oom score for a process. It returns 0 (zero) if either
// no oom score is set, or a sore is set to 0.
func GetOOMScoreAdj(pid int) (int, error) {
path := fmt.Sprintf("/proc/%d/oom_score_adj", pid)
data, err := ioutil.ReadFile(path)

View File

@ -71,9 +71,11 @@ func TestSetOOMScoreBoundaries(t *testing.T) {
score, err := GetOOMScoreAdj(os.Getpid())
assert.NilError(t, err)
if score == 0 || score == OOMScoreAdjMin {
// we won't be able to set the score lower than the parent process,
// so only test if parent process does not have a oom-score-adj
if score == OOMScoreAdjMin {
// We won't be able to set the score lower than the parent process. This
// could also be tested if the parent process does not have a oom-score-adj
// set, but GetOOMScoreAdj does not distinguish between "not set" and
// "score is set, but zero".
_, adjustment, err = adjustOom(OOMScoreAdjMin)
assert.NilError(t, err)
assert.Check(t, is.Equal(adjustment, OOMScoreAdjMin))