This fix migrates tests in integration-cli/docker_cli_oom_killed_test.go
to api tests.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,30 +0,0 @@ |
| 1 |
-// +build !windows |
|
| 2 |
- |
|
| 3 |
-package main |
|
| 4 |
- |
|
| 5 |
-import ( |
|
| 6 |
- "github.com/docker/docker/integration-cli/checker" |
|
| 7 |
- "github.com/go-check/check" |
|
| 8 |
-) |
|
| 9 |
- |
|
| 10 |
-func (s *DockerSuite) TestInspectOomKilledTrue(c *check.C) {
|
|
| 11 |
- testRequires(c, DaemonIsLinux, memoryLimitSupport, swapMemorySupport) |
|
| 12 |
- |
|
| 13 |
- name := "testoomkilled" |
|
| 14 |
- _, exitCode, _ := dockerCmdWithError("run", "--name", name, "--memory", "32MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done")
|
|
| 15 |
- |
|
| 16 |
- c.Assert(exitCode, checker.Equals, 137, check.Commentf("OOM exit should be 137"))
|
|
| 17 |
- |
|
| 18 |
- oomKilled := inspectField(c, name, "State.OOMKilled") |
|
| 19 |
- c.Assert(oomKilled, checker.Equals, "true") |
|
| 20 |
-} |
|
| 21 |
- |
|
| 22 |
-func (s *DockerSuite) TestInspectOomKilledFalse(c *check.C) {
|
|
| 23 |
- testRequires(c, DaemonIsLinux, memoryLimitSupport, swapMemorySupport) |
|
| 24 |
- |
|
| 25 |
- name := "testoomkilled" |
|
| 26 |
- dockerCmd(c, "run", "--name", name, "--memory", "32MB", "busybox", "sh", "-c", "echo hello world") |
|
| 27 |
- |
|
| 28 |
- oomKilled := inspectField(c, name, "State.OOMKilled") |
|
| 29 |
- c.Assert(oomKilled, checker.Equals, "false") |
|
| 30 |
-} |
| ... | ... |
@@ -11,6 +11,7 @@ import ( |
| 11 | 11 |
"github.com/docker/docker/integration/internal/request" |
| 12 | 12 |
"github.com/gotestyourself/gotestyourself/poll" |
| 13 | 13 |
"github.com/gotestyourself/gotestyourself/skip" |
| 14 |
+ "github.com/stretchr/testify/assert" |
|
| 14 | 15 |
"github.com/stretchr/testify/require" |
| 15 | 16 |
) |
| 16 | 17 |
|
| ... | ... |
@@ -146,3 +147,39 @@ func TestKillDifferentUserContainer(t *testing.T) {
|
| 146 | 146 |
require.NoError(t, err) |
| 147 | 147 |
poll.WaitOn(t, containerIsInState(ctx, client, id, "exited"), poll.WithDelay(100*time.Millisecond)) |
| 148 | 148 |
} |
| 149 |
+ |
|
| 150 |
+func TestInspectOomKilledTrue(t *testing.T) {
|
|
| 151 |
+ skip.If(t, testEnv.DaemonInfo.OSType != "linux" || !testEnv.DaemonInfo.MemoryLimit || !testEnv.DaemonInfo.SwapLimit) |
|
| 152 |
+ |
|
| 153 |
+ defer setupTest(t)() |
|
| 154 |
+ ctx := context.Background() |
|
| 155 |
+ client := request.NewAPIClient(t) |
|
| 156 |
+ |
|
| 157 |
+ name := "testoomkilled" |
|
| 158 |
+ 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) {
|
|
| 159 |
+ c.HostConfig.Resources.Memory = 32 * 1024 * 1024 |
|
| 160 |
+ }) |
|
| 161 |
+ |
|
| 162 |
+ poll.WaitOn(t, containerIsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) |
|
| 163 |
+ |
|
| 164 |
+ inspect, err := client.ContainerInspect(ctx, cID) |
|
| 165 |
+ require.NoError(t, err) |
|
| 166 |
+ assert.Equal(t, inspect.State.OOMKilled, true) |
|
| 167 |
+} |
|
| 168 |
+ |
|
| 169 |
+func TestInspectOomKilledFalse(t *testing.T) {
|
|
| 170 |
+ skip.If(t, testEnv.DaemonInfo.OSType != "linux" || !testEnv.DaemonInfo.MemoryLimit || !testEnv.DaemonInfo.SwapLimit) |
|
| 171 |
+ |
|
| 172 |
+ defer setupTest(t)() |
|
| 173 |
+ ctx := context.Background() |
|
| 174 |
+ client := request.NewAPIClient(t) |
|
| 175 |
+ |
|
| 176 |
+ name := "testoomkilled" |
|
| 177 |
+ cID := container.Run(t, ctx, client, container.WithName(name), container.WithCmd("sh", "-c", "echo hello world"))
|
|
| 178 |
+ |
|
| 179 |
+ poll.WaitOn(t, containerIsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) |
|
| 180 |
+ |
|
| 181 |
+ inspect, err := client.ContainerInspect(ctx, cID) |
|
| 182 |
+ require.NoError(t, err) |
|
| 183 |
+ assert.Equal(t, inspect.State.OOMKilled, false) |
|
| 184 |
+} |