2018-02-11 17:32:15 -05:00
|
|
|
package container // import "github.com/docker/docker/integration/container"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
containertypes "github.com/docker/docker/api/types/container"
|
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
|
|
|
"gotest.tools/poll"
|
2018-02-11 17:32:15 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUpdateRestartPolicy(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2018-02-11 17:32:15 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
cID := container.Run(t, ctx, client, container.WithCmd("sh", "-c", "sleep 1 && false"), func(c *container.TestContainerConfig) {
|
|
|
|
c.HostConfig.RestartPolicy = containertypes.RestartPolicy{
|
|
|
|
Name: "on-failure",
|
|
|
|
MaximumRetryCount: 3,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
_, err := client.ContainerUpdate(ctx, cID, containertypes.UpdateConfig{
|
|
|
|
RestartPolicy: containertypes.RestartPolicy{
|
|
|
|
Name: "on-failure",
|
|
|
|
MaximumRetryCount: 5,
|
|
|
|
},
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-11 17:32:15 -05:00
|
|
|
|
|
|
|
timeout := 60 * time.Second
|
|
|
|
if testEnv.OSType == "windows" {
|
|
|
|
timeout = 180 * time.Second
|
|
|
|
}
|
|
|
|
|
2018-02-22 05:30:51 -05:00
|
|
|
poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(timeout))
|
2018-02-11 17:32:15 -05:00
|
|
|
|
|
|
|
inspect, err := client.ContainerInspect(ctx, cID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(inspect.RestartCount, 5))
|
|
|
|
assert.Check(t, is.Equal(inspect.HostConfig.RestartPolicy.MaximumRetryCount, 5))
|
2018-02-11 17:32:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateRestartWithAutoRemove(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2018-02-11 17:32:15 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
cID := container.Run(t, ctx, client, func(c *container.TestContainerConfig) {
|
|
|
|
c.HostConfig.AutoRemove = true
|
|
|
|
})
|
|
|
|
|
|
|
|
_, err := client.ContainerUpdate(ctx, cID, containertypes.UpdateConfig{
|
|
|
|
RestartPolicy: containertypes.RestartPolicy{
|
|
|
|
Name: "always",
|
|
|
|
},
|
|
|
|
})
|
2018-05-20 18:06:50 -04:00
|
|
|
assert.Check(t, is.ErrorContains(err, "Restart policy cannot be updated because AutoRemove is enabled for the container"))
|
2018-02-11 17:32:15 -05:00
|
|
|
}
|