Merge pull request #36261 from yongtang/02082018-oom-killed
Migrate docker_cli_oom_killed_test.go to api tests
This commit is contained in:
commit
1bb389121d
2 changed files with 37 additions and 30 deletions
|
@ -1,30 +0,0 @@
|
|||
// +build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestInspectOomKilledTrue(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, memoryLimitSupport, swapMemorySupport)
|
||||
|
||||
name := "testoomkilled"
|
||||
_, exitCode, _ := dockerCmdWithError("run", "--name", name, "--memory", "32MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done")
|
||||
|
||||
c.Assert(exitCode, checker.Equals, 137, check.Commentf("OOM exit should be 137"))
|
||||
|
||||
oomKilled := inspectField(c, name, "State.OOMKilled")
|
||||
c.Assert(oomKilled, checker.Equals, "true")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectOomKilledFalse(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, memoryLimitSupport, swapMemorySupport)
|
||||
|
||||
name := "testoomkilled"
|
||||
dockerCmd(c, "run", "--name", name, "--memory", "32MB", "busybox", "sh", "-c", "echo hello world")
|
||||
|
||||
oomKilled := inspectField(c, name, "State.OOMKilled")
|
||||
c.Assert(oomKilled, checker.Equals, "false")
|
||||
}
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/docker/docker/integration/internal/request"
|
||||
"github.com/gotestyourself/gotestyourself/poll"
|
||||
"github.com/gotestyourself/gotestyourself/skip"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -146,3 +147,39 @@ func TestKillDifferentUserContainer(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
poll.WaitOn(t, containerIsInState(ctx, client, id, "exited"), poll.WithDelay(100*time.Millisecond))
|
||||
}
|
||||
|
||||
func TestInspectOomKilledTrue(t *testing.T) {
|
||||
skip.If(t, testEnv.DaemonInfo.OSType != "linux" || !testEnv.DaemonInfo.MemoryLimit || !testEnv.DaemonInfo.SwapLimit)
|
||||
|
||||
defer setupTest(t)()
|
||||
ctx := context.Background()
|
||||
client := request.NewAPIClient(t)
|
||||
|
||||
name := "testoomkilled"
|
||||
cID := container.Run(t, ctx, client, container.WithName(name), container.WithCmd("sh", "-c", "x=a; while true; do x=$x$x$x$x; done"), func(c *container.TestContainerConfig) {
|
||||
c.HostConfig.Resources.Memory = 32 * 1024 * 1024
|
||||
})
|
||||
|
||||
poll.WaitOn(t, containerIsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond))
|
||||
|
||||
inspect, err := client.ContainerInspect(ctx, cID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, inspect.State.OOMKilled, true)
|
||||
}
|
||||
|
||||
func TestInspectOomKilledFalse(t *testing.T) {
|
||||
skip.If(t, testEnv.DaemonInfo.OSType != "linux" || !testEnv.DaemonInfo.MemoryLimit || !testEnv.DaemonInfo.SwapLimit)
|
||||
|
||||
defer setupTest(t)()
|
||||
ctx := context.Background()
|
||||
client := request.NewAPIClient(t)
|
||||
|
||||
name := "testoomkilled"
|
||||
cID := container.Run(t, ctx, client, container.WithName(name), container.WithCmd("sh", "-c", "echo hello world"))
|
||||
|
||||
poll.WaitOn(t, containerIsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond))
|
||||
|
||||
inspect, err := client.ContainerInspect(ctx, cID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, inspect.State.OOMKilled, false)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue