From af2fb4eb777880fda0ba9004422d70742f4df7c1 Mon Sep 17 00:00:00 2001 From: Phil Estes Date: Tue, 10 Nov 2020 10:55:00 -0500 Subject: [PATCH] Allow oom adj test to run in environments with a score GitHub Actions process wrapper sets score adj to 500 for any process; the OOM score adj test expected default adj to be 0 during test. Signed-off-by: Phil Estes --- sys/oom_unix_test.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sys/oom_unix_test.go b/sys/oom_unix_test.go index 9bad2db53f2f..e6be852bcbf2 100644 --- a/sys/oom_unix_test.go +++ b/sys/oom_unix_test.go @@ -30,7 +30,7 @@ import ( ) func TestSetPositiveOomScoreAdjustment(t *testing.T) { - adjustment, err := adjustOom(123) + _, adjustment, err := adjustOom(123) if err != nil { t.Error(err) return @@ -44,7 +44,7 @@ func TestSetNegativeOomScoreAdjustmentWhenPrivileged(t *testing.T) { return } - adjustment, err := adjustOom(-123) + _, adjustment, err := adjustOom(-123) if err != nil { t.Error(err) return @@ -58,32 +58,37 @@ func TestSetNegativeOomScoreAdjustmentWhenUnprivilegedHasNoEffect(t *testing.T) return } - adjustment, err := adjustOom(-123) + initial, adjustment, err := adjustOom(-123) if err != nil { t.Error(err) return } - assert.Check(t, is.Equal(adjustment, 0)) + assert.Check(t, is.Equal(adjustment, initial)) } -func adjustOom(adjustment int) (int, error) { +func adjustOom(adjustment int) (int, int, error) { cmd := exec.Command("sleep", "100") if err := cmd.Start(); err != nil { - return 0, err + return 0, 0, err } defer cmd.Process.Kill() pid, err := waitForPid(cmd.Process) if err != nil { - return 0, err + return 0, 0, err + } + initial, err := GetOOMScoreAdj(pid) + if err != nil { + return 0, 0, err } if err := SetOOMScore(pid, adjustment); err != nil { - return 0, err + return 0, 0, err } - return GetOOMScoreAdj(pid) + adj, err := GetOOMScoreAdj(pid) + return initial, adj, err } func waitForPid(process *os.Process) (int, error) {