Skip to content

Commit 6e72715

Browse files
committed
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 <[email protected]>
1 parent badd60d commit 6e72715

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

sys/oom_linux_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ import (
2323
"testing"
2424
"time"
2525

26+
"github.com/containerd/containerd/pkg/userns"
2627
"gotest.tools/v3/assert"
2728
is "gotest.tools/v3/assert/cmp"
2829
)
2930

3031
func TestSetPositiveOomScoreAdjustment(t *testing.T) {
32+
// Setting a *positive* OOM score adjust does not require privileged
3133
_, adjustment, err := adjustOom(123)
3234
if err != nil {
3335
t.Error(err)
@@ -37,8 +39,8 @@ func TestSetPositiveOomScoreAdjustment(t *testing.T) {
3739
}
3840

3941
func TestSetNegativeOomScoreAdjustmentWhenPrivileged(t *testing.T) {
40-
if !runningPrivileged() {
41-
t.Skip("Needs to be run as root")
42+
if !runningPrivileged() || userns.RunningInUserNS() {
43+
t.Skip("requires root and not running in user namespace")
4244
return
4345
}
4446

@@ -51,8 +53,8 @@ func TestSetNegativeOomScoreAdjustmentWhenPrivileged(t *testing.T) {
5153
}
5254

5355
func TestSetNegativeOomScoreAdjustmentWhenUnprivilegedHasNoEffect(t *testing.T) {
54-
if runningPrivileged() {
55-
t.Skip("Needs to be run as non-root")
56+
if runningPrivileged() && !userns.RunningInUserNS() {
57+
t.Skip("needs to be run as non-root or in user namespace")
5658
return
5759
}
5860

0 commit comments

Comments
 (0)