Fix Memory Limit test
Modify the memory limit test, allowing the test to pass when swap is not enabled. Signed-off-by: James Jenkins <James.Jenkins@ibm.com>
This commit is contained in:
parent
bbcfbf2189
commit
b1c5c57be0
@ -30,6 +30,7 @@ import (
|
|||||||
cgroupsv2 "github.com/containerd/cgroups/v3/cgroup2"
|
cgroupsv2 "github.com/containerd/cgroups/v3/cgroup2"
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/integration/images"
|
"github.com/containerd/containerd/integration/images"
|
||||||
|
criopts "github.com/containerd/containerd/pkg/cri/opts"
|
||||||
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -232,8 +233,11 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
|
|||||||
EnsureImageExists(t, pauseImage)
|
EnsureImageExists(t, pauseImage)
|
||||||
|
|
||||||
expectedSwapLimit := func(memoryLimit int64) *int64 {
|
expectedSwapLimit := func(memoryLimit int64) *int64 {
|
||||||
|
if criopts.SwapControllerAvailable() {
|
||||||
return &memoryLimit
|
return &memoryLimit
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
t.Log("Create a container with memory limit")
|
t.Log("Create a container with memory limit")
|
||||||
cnConfig := ContainerConfig(
|
cnConfig := ContainerConfig(
|
||||||
@ -274,8 +278,10 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
|
|||||||
t.Log("Check memory limit in cgroup")
|
t.Log("Check memory limit in cgroup")
|
||||||
memLimit := getCgroupMemoryLimitForTask(t, task)
|
memLimit := getCgroupMemoryLimitForTask(t, task)
|
||||||
assert.Equal(t, uint64(400*1024*1024), memLimit)
|
assert.Equal(t, uint64(400*1024*1024), memLimit)
|
||||||
|
if criopts.SwapControllerAvailable() {
|
||||||
swapLimit := getCgroupSwapLimitForTask(t, task)
|
swapLimit := getCgroupSwapLimitForTask(t, task)
|
||||||
assert.Equal(t, uint64(400*1024*1024), swapLimit)
|
assert.Equal(t, uint64(400*1024*1024), swapLimit)
|
||||||
|
}
|
||||||
|
|
||||||
t.Log("Update container memory limit after started")
|
t.Log("Update container memory limit after started")
|
||||||
err = runtimeService.UpdateContainerResources(cn, &runtime.LinuxContainerResources{
|
err = runtimeService.UpdateContainerResources(cn, &runtime.LinuxContainerResources{
|
||||||
@ -292,8 +298,10 @@ func TestUpdateContainerResources_MemoryLimit(t *testing.T) {
|
|||||||
t.Log("Check memory limit in cgroup")
|
t.Log("Check memory limit in cgroup")
|
||||||
memLimit = getCgroupMemoryLimitForTask(t, task)
|
memLimit = getCgroupMemoryLimitForTask(t, task)
|
||||||
assert.Equal(t, uint64(800*1024*1024), memLimit)
|
assert.Equal(t, uint64(800*1024*1024), memLimit)
|
||||||
swapLimit = getCgroupSwapLimitForTask(t, task)
|
if criopts.SwapControllerAvailable() {
|
||||||
|
swapLimit := getCgroupSwapLimitForTask(t, task)
|
||||||
assert.Equal(t, uint64(800*1024*1024), swapLimit)
|
assert.Equal(t, uint64(800*1024*1024), swapLimit)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user