diff --git a/Makefile b/Makefile index 2248e87ba..4dc6b9f9a 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,9 @@ GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null) LDFLAGS := -X github.com/docker/containerd.GitCommit=${GIT_COMMIT} ${LDFLAGS} +TEST_TIMEOUT ?= 5m +TEST_SUITE_TIMEOUT ?= 10m + # if this session isn't interactive, then we don't want to allocate a # TTY, which would fail, but if it is interactive, we do want to attach # so that the user can send e.g. ^C through. @@ -84,7 +87,7 @@ test: all validate ifneq ($(wildcard /.dockerenv), ) $(MAKE) install bundles-rootfs cd integration-test ; \ - go test -check.v $(TESTFLAGS) github.com/docker/containerd/integration-test + go test -check.v -check.timeout=$(TEST_TIMEOUT) timeout=$(TEST_SUITE_TIMEOUT) $(TESTFLAGS) github.com/docker/containerd/integration-test endif validate: fmt diff --git a/integration-test/check_test.go b/integration-test/check_test.go index 23508e714..a3214aab1 100644 --- a/integration-test/check_test.go +++ b/integration-test/check_test.go @@ -223,6 +223,10 @@ func (cs *ContainerdSuite) TearDownTest(c *check.C) { fmt.Fprintf(os.Stderr, "Failed to cleanup leftover test containers: %v", err) } - <-ch + select { + case <-ch: + case <-time.After(3 * time.Second): + fmt.Fprintf(os.Stderr, "TearDownTest: Containerd %v didn't die after 3 seconds", ctr.Id) + } } } diff --git a/integration-test/container_utils_test.go b/integration-test/container_utils_test.go index b3429e382..4dff21ba7 100644 --- a/integration-test/container_utils_test.go +++ b/integration-test/container_utils_test.go @@ -110,12 +110,21 @@ func (c *containerProcess) openIo() (err error) { return nil } +func (c *containerProcess) GetEventsChannel() chan *types.Event { + return c.eventsCh +} + func (c *containerProcess) GetNextEvent() *types.Event { + if c.hasExited { + return nil + } + e := <-c.eventsCh if e.Type == "exit" && e.Pid == c.pid { c.Cleanup() c.hasExited = true + close(c.eventsCh) } return e diff --git a/integration-test/start_test.go b/integration-test/start_test.go index 8d1af0876..db4f81fc3 100644 --- a/integration-test/start_test.go +++ b/integration-test/start_test.go @@ -1,6 +1,9 @@ package main import ( + "time" + + "github.com/docker/containerd/api/grpc/types" "github.com/docker/docker/pkg/integration/checker" "github.com/go-check/check" ) @@ -40,11 +43,11 @@ var func (cs *ContainerdSuite) TestStartBusyboxNoSuchFile(t *check.C) { expectedOutput := `oci runtime error: exec: \"NoSuchFile\": executable file not found in $PATH` - if err := CreateBusyboxBundle("busybox-NoSuchFile", []string{"NoSuchFile"}); err != nil { + if err := CreateBusyboxBundle("busybox-no-such-file", []string{"NoSuchFile"}); err != nil { t.Fatal(err) } - _, err := cs.RunContainer("NoSuchFile", "busybox-NoSuchFile") + _, err := cs.RunContainer("NoSuchFile", "busybox-no-such-file") t.Assert(err.Error(), checker.Contains, expectedOutput) } @@ -56,3 +59,40 @@ func (cs *ContainerdSuite) TestStartBusyboxTop(t *check.C) { _, err := cs.StartContainer("top", "busybox-top") t.Assert(err, checker.Equals, nil) } + +func (cs *ContainerdSuite) TestStartBusyboxLsEvents(t *check.C) { + if err := CreateBusyboxBundle("busybox-ls", []string{"ls"}); err != nil { + t.Fatal(err) + } + + containerId := "ls-events" + c, err := cs.StartContainer(containerId, "busybox-ls") + if err != nil { + t.Fatal(err) + } + + for _, evt := range []types.Event{ + { + Type: "start-container", + Id: containerId, + Status: 0, + Pid: "", + }, + { + Type: "exit", + Id: containerId, + Status: 0, + Pid: "init", + }, + } { + ch := c.GetEventsChannel() + select { + case e := <-ch: + evt.Timestamp = e.Timestamp + + t.Assert(*e, checker.Equals, evt) + case <-time.After(2 * time.Second): + t.Fatal("Container took more than 2 seconds to terminate") + } + } +}