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+
3564func 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