Skip to content

Commit

Permalink
Allow oom adj test to run in environments with a score
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
estesp committed Nov 19, 2020
1 parent c11472d commit af2fb4e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions sys/oom_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit af2fb4e

Please sign in to comment.