From 6e727152261bd22fbf7da87392cf2e3c7dc16df5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 23 Mar 2021 11:20:23 +0100 Subject: [PATCH] sys: add missing pre-condition checks in tests SetOOMScore requires both privileged (root) and non-user namespace, for negative values, so adjust the pre-conditions accordingly. Signed-off-by: Sebastiaan van Stijn --- sys/oom_linux_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sys/oom_linux_test.go b/sys/oom_linux_test.go index cc9d123ef..dcc0ceddd 100644 --- a/sys/oom_linux_test.go +++ b/sys/oom_linux_test.go @@ -23,11 +23,13 @@ import ( "testing" "time" + "github.com/containerd/containerd/pkg/userns" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) func TestSetPositiveOomScoreAdjustment(t *testing.T) { + // Setting a *positive* OOM score adjust does not require privileged _, adjustment, err := adjustOom(123) if err != nil { t.Error(err) @@ -37,8 +39,8 @@ func TestSetPositiveOomScoreAdjustment(t *testing.T) { } func TestSetNegativeOomScoreAdjustmentWhenPrivileged(t *testing.T) { - if !runningPrivileged() { - t.Skip("Needs to be run as root") + if !runningPrivileged() || userns.RunningInUserNS() { + t.Skip("requires root and not running in user namespace") return } @@ -51,8 +53,8 @@ func TestSetNegativeOomScoreAdjustmentWhenPrivileged(t *testing.T) { } func TestSetNegativeOomScoreAdjustmentWhenUnprivilegedHasNoEffect(t *testing.T) { - if runningPrivileged() { - t.Skip("Needs to be run as non-root") + if runningPrivileged() && !userns.RunningInUserNS() { + t.Skip("needs to be run as non-root or in user namespace") return }