diff options
author | Paweł Gronowski <pawel.gronowski@docker.com> | 2022-07-04 12:02:43 +0200 |
---|---|---|
committer | Paweł Gronowski <pawel.gronowski@docker.com> | 2022-07-20 09:23:31 +0200 |
commit | 5571d5139b5c075dd5a99add00aa289a4ab10444 (patch) | |
tree | 657ffdac955cf264f475b65cd1d25c4f9581e157 /integration | |
parent | 498803bec9a75474b482b429eb6e9c030abce3d1 (diff) |
integration: TestWaitRestartedContainer
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Diffstat (limited to 'integration')
-rw-r--r-- | integration/container/wait_test.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/integration/container/wait_test.go b/integration/container/wait_test.go index 6ac6b21299..12a9313caa 100644 --- a/integration/container/wait_test.go +++ b/integration/container/wait_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/docker/docker/api/types" containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/testutil/request" @@ -156,3 +157,69 @@ func TestWaitConditions(t *testing.T) { }) } } + +func TestWaitRestartedContainer(t *testing.T) { + defer setupTest(t)() + cli := request.NewAPIClient(t) + + testCases := []struct { + doc string + waitCond containertypes.WaitCondition + }{ + { + doc: "default", + }, + { + doc: "not-running", + waitCond: containertypes.WaitConditionNotRunning, + }, + { + doc: "next-exit", + waitCond: containertypes.WaitConditionNextExit, + }, + } + + // We can't catch the SIGTERM in the Windows based busybox image + isWindowDaemon := testEnv.DaemonInfo.OSType == "windows" + + for _, tc := range testCases { + tc := tc + t.Run(tc.doc, func(t *testing.T) { + t.Parallel() + ctx := context.Background() + containerID := container.Run(ctx, t, cli, + container.WithCmd("sh", "-c", "trap 'exit 5' SIGTERM; while true; do sleep 0.1; done"), + ) + defer cli.ContainerRemove(ctx, containerID, types.ContainerRemoveOptions{Force: true}) + + poll.WaitOn(t, container.IsInState(ctx, cli, containerID, "running"), poll.WithTimeout(30*time.Second), poll.WithDelay(100*time.Millisecond)) + + // Container is running now, wait for exit + waitResC, errC := cli.ContainerWait(ctx, containerID, tc.waitCond) + + timeout := 5 + // On Windows it will always timeout, because our process won't receive SIGTERM + // Skip to force killing immediately + if isWindowDaemon { + timeout = 0 + } + + err := cli.ContainerRestart(ctx, containerID, containertypes.StopOptions{Timeout: &timeout, Signal: "SIGTERM"}) + assert.NilError(t, err) + + select { + case err := <-errC: + t.Fatalf("Unexpected error: %v", err) + case <-time.After(time.Second * 3): + t.Fatalf("Wait should end after restart") + case waitRes := <-waitResC: + expectedCode := int64(5) + + if !isWindowDaemon { + assert.Check(t, is.Equal(expectedCode, waitRes.StatusCode)) + } + } + }) + } + +} |