Move kill health test to integration
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
da574f9343
commit
f8aef6a92f
2 changed files with 29 additions and 26 deletions
|
@ -165,29 +165,3 @@ ENTRYPOINT /bin/sh -c "sleep 600"`))
|
|||
waitForHealthStatus(c, name, "starting", "healthy")
|
||||
|
||||
}
|
||||
|
||||
// GitHub #37263
|
||||
func (s *DockerSuite) TestHealthKillContainer(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows
|
||||
|
||||
imageName := "testhealth"
|
||||
buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox
|
||||
HEALTHCHECK --interval=1s --timeout=5s --retries=5 CMD /bin/sh -c "sleep 1"
|
||||
ENTRYPOINT /bin/sh -c "sleep 600"`))
|
||||
|
||||
name := "test_health_kill"
|
||||
dockerCmd(c, "run", "-d", "--name", name, imageName)
|
||||
defer func() {
|
||||
dockerCmd(c, "rm", "-f", name)
|
||||
dockerCmd(c, "rmi", imageName)
|
||||
}()
|
||||
|
||||
// Start
|
||||
dockerCmd(c, "start", name)
|
||||
waitForHealthStatus(c, name, "starting", "healthy")
|
||||
|
||||
dockerCmd(c, "kill", "-s", "SIGINT", name)
|
||||
out, _ := dockerCmd(c, "inspect", "--format={{.State.Health.Status}}", name)
|
||||
c.Check(out, checker.Equals, "healthy\n")
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/integration/internal/container"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/poll"
|
||||
"gotest.tools/skip"
|
||||
)
|
||||
|
@ -32,6 +33,34 @@ func TestHealthCheckWorkdir(t *testing.T) {
|
|||
poll.WaitOn(t, pollForHealthStatus(ctx, client, cID, types.Healthy), poll.WithDelay(100*time.Millisecond))
|
||||
}
|
||||
|
||||
// GitHub #37263
|
||||
// Do not stop healthchecks just because we sent a signal to the container
|
||||
func TestHealthKillContainer(t *testing.T) {
|
||||
defer setupTest(t)()
|
||||
|
||||
ctx := context.Background()
|
||||
client := testEnv.APIClient()
|
||||
|
||||
id := container.Run(ctx, t, client, func(c *container.TestContainerConfig) {
|
||||
c.Config.Healthcheck = &containertypes.HealthConfig{
|
||||
Test: []string{"CMD-SHELL", "sleep 1"},
|
||||
Interval: time.Second,
|
||||
Retries: 5,
|
||||
}
|
||||
})
|
||||
|
||||
ctxPoll, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
poll.WaitOn(t, pollForHealthStatus(ctxPoll, client, id, "healthy"), poll.WithDelay(100*time.Millisecond))
|
||||
|
||||
err := client.ContainerKill(ctx, id, "SIGUSR1")
|
||||
assert.NilError(t, err)
|
||||
|
||||
ctxPoll, cancel = context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
poll.WaitOn(t, pollForHealthStatus(ctxPoll, client, id, "healthy"), poll.WithDelay(100*time.Millisecond))
|
||||
}
|
||||
|
||||
func pollForHealthStatus(ctx context.Context, client client.APIClient, containerID string, healthStatus string) func(log poll.LogT) poll.Result {
|
||||
return func(log poll.LogT) poll.Result {
|
||||
inspect, err := client.ContainerInspect(ctx, containerID)
|
||||
|
|
Loading…
Reference in a new issue