Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit f8aef6a92f5961f2615ada37b7d108774a0821e0)
Signed-off-by: Dani Louca <dani.louca@docker.com>
| ... | ... |
@@ -165,29 +165,3 @@ ENTRYPOINT /bin/sh -c "sleep 600"`)) |
| 165 | 165 |
waitForHealthStatus(c, name, "starting", "healthy") |
| 166 | 166 |
|
| 167 | 167 |
} |
| 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 |
-} |
| ... | ... |
@@ -9,6 +9,7 @@ import ( |
| 9 | 9 |
containertypes "github.com/docker/docker/api/types/container" |
| 10 | 10 |
"github.com/docker/docker/client" |
| 11 | 11 |
"github.com/docker/docker/integration/internal/container" |
| 12 |
+ "gotest.tools/assert" |
|
| 12 | 13 |
"gotest.tools/poll" |
| 13 | 14 |
"gotest.tools/skip" |
| 14 | 15 |
) |
| ... | ... |
@@ -32,6 +33,34 @@ func TestHealthCheckWorkdir(t *testing.T) {
|
| 32 | 32 |
poll.WaitOn(t, pollForHealthStatus(ctx, client, cID, types.Healthy), poll.WithDelay(100*time.Millisecond)) |
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 |
+// GitHub #37263 |
|
| 36 |
+// Do not stop healthchecks just because we sent a signal to the container |
|
| 37 |
+func TestHealthKillContainer(t *testing.T) {
|
|
| 38 |
+ defer setupTest(t)() |
|
| 39 |
+ |
|
| 40 |
+ ctx := context.Background() |
|
| 41 |
+ client := testEnv.APIClient() |
|
| 42 |
+ |
|
| 43 |
+ id := container.Run(ctx, t, client, func(c *container.TestContainerConfig) {
|
|
| 44 |
+ c.Config.Healthcheck = &containertypes.HealthConfig{
|
|
| 45 |
+ Test: []string{"CMD-SHELL", "sleep 1"},
|
|
| 46 |
+ Interval: time.Second, |
|
| 47 |
+ Retries: 5, |
|
| 48 |
+ } |
|
| 49 |
+ }) |
|
| 50 |
+ |
|
| 51 |
+ ctxPoll, cancel := context.WithTimeout(ctx, 30*time.Second) |
|
| 52 |
+ defer cancel() |
|
| 53 |
+ poll.WaitOn(t, pollForHealthStatus(ctxPoll, client, id, "healthy"), poll.WithDelay(100*time.Millisecond)) |
|
| 54 |
+ |
|
| 55 |
+ err := client.ContainerKill(ctx, id, "SIGUSR1") |
|
| 56 |
+ assert.NilError(t, err) |
|
| 57 |
+ |
|
| 58 |
+ ctxPoll, cancel = context.WithTimeout(ctx, 30*time.Second) |
|
| 59 |
+ defer cancel() |
|
| 60 |
+ poll.WaitOn(t, pollForHealthStatus(ctxPoll, client, id, "healthy"), poll.WithDelay(100*time.Millisecond)) |
|
| 61 |
+} |
|
| 62 |
+ |
|
| 35 | 63 |
func pollForHealthStatus(ctx context.Context, client client.APIClient, containerID string, healthStatus string) func(log poll.LogT) poll.Result {
|
| 36 | 64 |
return func(log poll.LogT) poll.Result {
|
| 37 | 65 |
inspect, err := client.ContainerInspect(ctx, containerID) |