2018-02-09 19:13:26 -05:00
|
|
|
package container // import "github.com/docker/docker/integration/container"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/events"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
2018-05-04 17:15:00 -04:00
|
|
|
"github.com/docker/docker/api/types/versions"
|
2018-02-09 19:13:26 -05:00
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2019-08-29 16:52:40 -04:00
|
|
|
"github.com/docker/docker/testutil/request"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
"gotest.tools/v3/poll"
|
|
|
|
"gotest.tools/v3/skip"
|
2018-02-09 19:13:26 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPause(t *testing.T) {
|
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows" && testEnv.DaemonInfo.Isolation == "process")
|
2020-02-18 04:43:56 -05:00
|
|
|
skip.If(t, testEnv.DaemonInfo.CgroupDriver == "none")
|
2018-02-09 19:13:26 -05:00
|
|
|
|
|
|
|
defer setupTest(t)()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2018-02-09 19:13:26 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2019-06-06 07:15:31 -04:00
|
|
|
cID := container.Run(ctx, t, client)
|
2018-02-22 05:30:51 -05:00
|
|
|
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
|
2018-02-09 19:13:26 -05:00
|
|
|
|
|
|
|
since := request.DaemonUnixTime(ctx, t, client, testEnv)
|
|
|
|
|
2018-03-02 08:45:14 -05:00
|
|
|
err := client.ContainerPause(ctx, cID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-09 19:13:26 -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(true, inspect.State.Paused))
|
2018-02-09 19:13:26 -05:00
|
|
|
|
2018-03-02 08:45:14 -05:00
|
|
|
err = client.ContainerUnpause(ctx, cID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-09 19:13:26 -05:00
|
|
|
|
|
|
|
until := request.DaemonUnixTime(ctx, t, client, testEnv)
|
|
|
|
|
|
|
|
messages, errs := client.Events(ctx, types.EventsOptions{
|
|
|
|
Since: since,
|
|
|
|
Until: until,
|
2018-03-02 08:45:14 -05:00
|
|
|
Filters: filters.NewArgs(filters.Arg("container", cID)),
|
2018-02-09 19:13:26 -05:00
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.DeepEqual([]string{"pause", "unpause"}, getEventActions(t, messages, errs)))
|
2018-02-09 19:13:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPauseFailsOnWindowsServerContainers(t *testing.T) {
|
2018-05-19 07:38:54 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType != "windows" || testEnv.DaemonInfo.Isolation != "process")
|
2018-02-09 19:13:26 -05:00
|
|
|
|
|
|
|
defer setupTest(t)()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2018-02-09 19:13:26 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2019-06-06 07:15:31 -04:00
|
|
|
cID := container.Run(ctx, t, client)
|
2018-02-22 05:30:51 -05:00
|
|
|
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
|
2018-02-09 19:13:26 -05:00
|
|
|
|
|
|
|
err := client.ContainerPause(ctx, cID)
|
2018-05-20 18:06:50 -04:00
|
|
|
assert.Check(t, is.ErrorContains(err, "cannot pause Windows Server Containers"))
|
2018-02-09 19:13:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPauseStopPausedContainer(t *testing.T) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
|
2018-05-04 17:15:00 -04:00
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.31"), "broken in earlier versions")
|
2020-02-18 04:43:56 -05:00
|
|
|
skip.If(t, testEnv.DaemonInfo.CgroupDriver == "none")
|
2018-02-09 19:13:26 -05:00
|
|
|
defer setupTest(t)()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2018-02-09 19:13:26 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2019-06-06 07:15:31 -04:00
|
|
|
cID := container.Run(ctx, t, client)
|
2018-02-22 05:30:51 -05:00
|
|
|
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
|
2018-02-09 19:13:26 -05:00
|
|
|
|
|
|
|
err := client.ContainerPause(ctx, cID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-09 19:13:26 -05:00
|
|
|
|
|
|
|
err = client.ContainerStop(ctx, cID, nil)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-09 19:13:26 -05:00
|
|
|
|
2018-02-22 05:30:51 -05:00
|
|
|
poll.WaitOn(t, container.IsStopped(ctx, client, cID), poll.WithDelay(100*time.Millisecond))
|
2018-02-09 19:13:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func getEventActions(t *testing.T, messages <-chan events.Message, errs <-chan error) []string {
|
2018-05-19 07:38:54 -04:00
|
|
|
var actions []string
|
2018-02-09 19:13:26 -05:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case err := <-errs:
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, err == nil || err == io.EOF)
|
2018-02-09 19:13:26 -05:00
|
|
|
return actions
|
|
|
|
case e := <-messages:
|
|
|
|
actions = append(actions, e.Status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|