2018-02-05 16:05:59 -05:00
|
|
|
package container // import "github.com/docker/docker/integration/container"
|
2018-01-02 23:55:33 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2018-02-10 18:01:37 -05:00
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
"gotest.tools/poll"
|
2018-01-02 23:55:33 -05:00
|
|
|
)
|
|
|
|
|
2018-01-29 18:36:45 -05:00
|
|
|
func TestStopContainerWithRestartPolicyAlways(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2018-01-29 18:36:45 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2018-03-21 17:47:49 -04:00
|
|
|
names := []string{"verifyRestart1-" + t.Name(), "verifyRestart2-" + t.Name()}
|
2018-01-29 18:36:45 -05:00
|
|
|
for _, name := range names {
|
2018-02-10 18:01:37 -05:00
|
|
|
container.Run(t, ctx, client, container.WithName(name), container.WithCmd("false"), func(c *container.TestContainerConfig) {
|
|
|
|
c.HostConfig.RestartPolicy.Name = "always"
|
|
|
|
})
|
2018-01-29 18:36:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range names {
|
2018-02-22 05:30:51 -05:00
|
|
|
poll.WaitOn(t, container.IsInState(ctx, client, name, "running", "restarting"), poll.WithDelay(100*time.Millisecond))
|
2018-01-29 18:36:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range names {
|
|
|
|
err := client.ContainerStop(ctx, name, nil)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-29 18:36:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range names {
|
2018-02-22 05:30:51 -05:00
|
|
|
poll.WaitOn(t, container.IsStopped(ctx, client, name), poll.WithDelay(100*time.Millisecond))
|
2018-01-29 18:36:45 -05:00
|
|
|
}
|
|
|
|
}
|