mirror of
https://github.com/docker/cli.git
synced 2026-09-27 17:56:04 -04:00
Merge pull request #36874 from kolyshkin/stop-timeout
daemon.ContainerStop(): fix for a negative timeout Upstream-commit: b85799b63fb25423620ed16e717a99401cd3a39b Component: engine
This commit is contained in:
@@ -3,6 +3,7 @@ package container // import "github.com/docker/docker/integration/container"
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -42,6 +43,60 @@ func TestStopContainerWithRestartPolicyAlways(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestStopContainerWithTimeout checks that ContainerStop with
|
||||
// a timeout works as documented, i.e. in case of negative timeout
|
||||
// waiting is not limited (issue #35311).
|
||||
func TestStopContainerWithTimeout(t *testing.T) {
|
||||
defer setupTest(t)()
|
||||
client := request.NewAPIClient(t)
|
||||
ctx := context.Background()
|
||||
|
||||
testCmd := container.WithCmd("sh", "-c", "sleep 2 && exit 42")
|
||||
testData := []struct {
|
||||
doc string
|
||||
timeout int
|
||||
expectedExitCode int
|
||||
}{
|
||||
// In case container is forcefully killed, 137 is returned,
|
||||
// otherwise the exit code from the above script
|
||||
{
|
||||
"zero timeout: expect forceful container kill",
|
||||
0, 137,
|
||||
},
|
||||
{
|
||||
"too small timeout: expect forceful container kill",
|
||||
1, 137,
|
||||
},
|
||||
{
|
||||
"big enough timeout: expect graceful container stop",
|
||||
3, 42,
|
||||
},
|
||||
{
|
||||
"unlimited timeout: expect graceful container stop",
|
||||
-1, 42,
|
||||
},
|
||||
}
|
||||
|
||||
for _, d := range testData {
|
||||
d := d
|
||||
t.Run(strconv.Itoa(d.timeout), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
id := container.Run(t, ctx, client, testCmd)
|
||||
|
||||
timeout := time.Duration(d.timeout) * time.Second
|
||||
err := client.ContainerStop(ctx, id, &timeout)
|
||||
assert.NilError(t, err)
|
||||
|
||||
poll.WaitOn(t, container.IsStopped(ctx, client, id),
|
||||
poll.WithDelay(100*time.Millisecond))
|
||||
|
||||
inspect, err := client.ContainerInspect(ctx, id)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, inspect.State.ExitCode, d.expectedExitCode)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteDevicemapper(t *testing.T) {
|
||||
skip.If(t, testEnv.DaemonInfo.Driver != "devicemapper")
|
||||
skip.If(t, testEnv.IsRemoteDaemon, "cannot start daemon on remote test run")
|
||||
|
||||
Reference in New Issue
Block a user