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,35 @@ 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+ skip .If (t , testEnv .OSType == "windows" , "Windows only supports SIGKILL and SIGTERM? See https://github.com/moby/moby/issues/39574" )
40+ defer setupTest (t )()
41+
42+ ctx := context .Background ()
43+ client := testEnv .APIClient ()
44+
45+ id := container .Run (t , ctx , client , func (c * container.TestContainerConfig ) {
46+ c .Config .Healthcheck = & containertypes.HealthConfig {
47+ Test : []string {"CMD-SHELL" , "sleep 1" },
48+ Interval : time .Second ,
49+ Retries : 5 ,
50+ }
51+ })
52+
53+ ctxPoll , cancel := context .WithTimeout (ctx , 30 * time .Second )
54+ defer cancel ()
55+ poll .WaitOn (t , pollForHealthStatus (ctxPoll , client , id , "healthy" ), poll .WithDelay (100 * time .Millisecond ))
56+
57+ err := client .ContainerKill (ctx , id , "SIGUSR1" )
58+ assert .NilError (t , err )
59+
60+ ctxPoll , cancel = context .WithTimeout (ctx , 30 * time .Second )
61+ defer cancel ()
62+ poll .WaitOn (t , pollForHealthStatus (ctxPoll , client , id , "healthy" ), poll .WithDelay (100 * time .Millisecond ))
63+ }
64+
3565func pollForHealthStatus (ctx context.Context , client client.APIClient , containerID string , healthStatus string ) func (log poll.LogT ) poll.Result {
3666 return func (log poll.LogT ) poll.Result {
3767 inspect , err := client .ContainerInspect (ctx , containerID )
0 commit comments