Skip to content

Commit 753bfd6

Browse files
author
Kazuyoshi Kato
authored
Merge pull request #7959 from Jenkins-J/fix-mem-limit-test
Fix Memory Limit test
2 parents 93a2823 + b1c5c57 commit 753bfd6

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

integration/container_update_resources_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
cgroupsv2 "github.com/containerd/cgroups/v3/cgroup2"
3131
"github.com/containerd/containerd"
3232
"github.com/containerd/containerd/integration/images"
33+
criopts "github.com/containerd/containerd/pkg/cri/opts"
3334
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
3435
"github.com/stretchr/testify/assert"
3536
"github.com/stretchr/testify/require"
@@ -232,7 +233,10 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
232233
EnsureImageExists(t, pauseImage)
233234

234235
expectedSwapLimit := func(memoryLimit int64) *int64 {
235-
return &memoryLimit
236+
if criopts.SwapControllerAvailable() {
237+
return &memoryLimit
238+
}
239+
return nil
236240
}
237241

238242
t.Log("Create a container with memory limit")
@@ -274,8 +278,10 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
274278
t.Log("Check memory limit in cgroup")
275279
memLimit := getCgroupMemoryLimitForTask(t, task)
276280
assert.Equal(t, uint64(400*1024*1024), memLimit)
277-
swapLimit := getCgroupSwapLimitForTask(t, task)
278-
assert.Equal(t, uint64(400*1024*1024), swapLimit)
281+
if criopts.SwapControllerAvailable() {
282+
swapLimit := getCgroupSwapLimitForTask(t, task)
283+
assert.Equal(t, uint64(400*1024*1024), swapLimit)
284+
}
279285

280286
t.Log("Update container memory limit after started")
281287
err = runtimeService.UpdateContainerResources(cn, &runtime.LinuxContainerResources{
@@ -292,8 +298,10 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
292298
t.Log("Check memory limit in cgroup")
293299
memLimit = getCgroupMemoryLimitForTask(t, task)
294300
assert.Equal(t, uint64(800*1024*1024), memLimit)
295-
swapLimit = getCgroupSwapLimitForTask(t, task)
296-
assert.Equal(t, uint64(800*1024*1024), swapLimit)
301+
if criopts.SwapControllerAvailable() {
302+
swapLimit := getCgroupSwapLimitForTask(t, task)
303+
assert.Equal(t, uint64(800*1024*1024), swapLimit)
304+
}
297305

298306
}
299307

0 commit comments

Comments
 (0)