Skip to content

Commit f8aef6a

Browse files
cpuguy83thaJeztah
authored andcommitted
Move kill health test to integration
Signed-off-by: Brian Goff <[email protected]>
1 parent da574f9 commit f8aef6a

2 files changed

Lines changed: 29 additions & 26 deletions

File tree

integration-cli/docker_cli_health_test.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -165,29 +165,3 @@ ENTRYPOINT /bin/sh -c "sleep 600"`))
165165
waitForHealthStatus(c, name, "starting", "healthy")
166166

167167
}
168-
169-
// GitHub #37263
170-
func (s *DockerSuite) TestHealthKillContainer(c *check.C) {
171-
testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows
172-
173-
imageName := "testhealth"
174-
buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox
175-
HEALTHCHECK --interval=1s --timeout=5s --retries=5 CMD /bin/sh -c "sleep 1"
176-
ENTRYPOINT /bin/sh -c "sleep 600"`))
177-
178-
name := "test_health_kill"
179-
dockerCmd(c, "run", "-d", "--name", name, imageName)
180-
defer func() {
181-
dockerCmd(c, "rm", "-f", name)
182-
dockerCmd(c, "rmi", imageName)
183-
}()
184-
185-
// Start
186-
dockerCmd(c, "start", name)
187-
waitForHealthStatus(c, name, "starting", "healthy")
188-
189-
dockerCmd(c, "kill", "-s", "SIGINT", name)
190-
out, _ := dockerCmd(c, "inspect", "--format={{.State.Health.Status}}", name)
191-
c.Check(out, checker.Equals, "healthy\n")
192-
193-
}

integration/container/health_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
containertypes "github.com/docker/docker/api/types/container"
1010
"github.com/docker/docker/client"
1111
"github.com/docker/docker/integration/internal/container"
12+
"gotest.tools/assert"
1213
"gotest.tools/poll"
1314
"gotest.tools/skip"
1415
)
@@ -32,6 +33,34 @@ func TestHealthCheckWorkdir(t *testing.T) {
3233
poll.WaitOn(t, pollForHealthStatus(ctx, client, cID, types.Healthy), poll.WithDelay(100*time.Millisecond))
3334
}
3435

36+
// GitHub #37263
37+
// Do not stop healthchecks just because we sent a signal to the container
38+
func TestHealthKillContainer(t *testing.T) {
39+
defer setupTest(t)()
40+
41+
ctx := context.Background()
42+
client := testEnv.APIClient()
43+
44+
id := container.Run(ctx, t, client, func(c *container.TestContainerConfig) {
45+
c.Config.Healthcheck = &containertypes.HealthConfig{
46+
Test: []string{"CMD-SHELL", "sleep 1"},
47+
Interval: time.Second,
48+
Retries: 5,
49+
}
50+
})
51+
52+
ctxPoll, cancel := context.WithTimeout(ctx, 30*time.Second)
53+
defer cancel()
54+
poll.WaitOn(t, pollForHealthStatus(ctxPoll, client, id, "healthy"), poll.WithDelay(100*time.Millisecond))
55+
56+
err := client.ContainerKill(ctx, id, "SIGUSR1")
57+
assert.NilError(t, err)
58+
59+
ctxPoll, cancel = context.WithTimeout(ctx, 30*time.Second)
60+
defer cancel()
61+
poll.WaitOn(t, pollForHealthStatus(ctxPoll, client, id, "healthy"), poll.WithDelay(100*time.Millisecond))
62+
}
63+
3564
func pollForHealthStatus(ctx context.Context, client client.APIClient, containerID string, healthStatus string) func(log poll.LogT) poll.Result {
3665
return func(log poll.LogT) poll.Result {
3766
inspect, err := client.ContainerInspect(ctx, containerID)

0 commit comments

Comments
 (0)