diff --git a/integration-cli/docker_cli_oom_killed_test.go b/integration-cli/docker_cli_oom_killed_test.go deleted file mode 100644 index 54c34d206a..0000000000 --- a/integration-cli/docker_cli_oom_killed_test.go +++ /dev/null @@ -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") -} diff --git a/integration/container/kill_test.go b/integration/container/kill_test.go index 6efc5fc61d..d399213ac6 100644 --- a/integration/container/kill_test.go +++ b/integration/container/kill_test.go @@ -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) +}