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