Merge pull request #167 from mlaventure/containers-life-events-test

Containers life events test
This commit is contained in:
Michael Crosby 2016-03-28 17:01:50 -07:00
commit 5b0a213766
4 changed files with 60 additions and 4 deletions

View file

@ -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} 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 # 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 # TTY, which would fail, but if it is interactive, we do want to attach
# so that the user can send e.g. ^C through. # so that the user can send e.g. ^C through.
@ -84,7 +87,7 @@ test: all validate
ifneq ($(wildcard /.dockerenv), ) ifneq ($(wildcard /.dockerenv), )
$(MAKE) install bundles-rootfs $(MAKE) install bundles-rootfs
cd integration-test ; \ 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 endif
validate: fmt validate: fmt

View file

@ -223,6 +223,10 @@ func (cs *ContainerdSuite) TearDownTest(c *check.C) {
fmt.Fprintf(os.Stderr, "Failed to cleanup leftover test containers: %v", err) 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)
}
} }
} }

View file

@ -110,12 +110,21 @@ func (c *containerProcess) openIo() (err error) {
return nil return nil
} }
func (c *containerProcess) GetEventsChannel() chan *types.Event {
return c.eventsCh
}
func (c *containerProcess) GetNextEvent() *types.Event { func (c *containerProcess) GetNextEvent() *types.Event {
if c.hasExited {
return nil
}
e := <-c.eventsCh e := <-c.eventsCh
if e.Type == "exit" && e.Pid == c.pid { if e.Type == "exit" && e.Pid == c.pid {
c.Cleanup() c.Cleanup()
c.hasExited = true c.hasExited = true
close(c.eventsCh)
} }
return e return e

View file

@ -1,6 +1,9 @@
package main package main
import ( import (
"time"
"github.com/docker/containerd/api/grpc/types"
"github.com/docker/docker/pkg/integration/checker" "github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -40,11 +43,11 @@ var
func (cs *ContainerdSuite) TestStartBusyboxNoSuchFile(t *check.C) { func (cs *ContainerdSuite) TestStartBusyboxNoSuchFile(t *check.C) {
expectedOutput := `oci runtime error: exec: \"NoSuchFile\": executable file not found in $PATH` 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) t.Fatal(err)
} }
_, err := cs.RunContainer("NoSuchFile", "busybox-NoSuchFile") _, err := cs.RunContainer("NoSuchFile", "busybox-no-such-file")
t.Assert(err.Error(), checker.Contains, expectedOutput) t.Assert(err.Error(), checker.Contains, expectedOutput)
} }
@ -56,3 +59,40 @@ func (cs *ContainerdSuite) TestStartBusyboxTop(t *check.C) {
_, err := cs.StartContainer("top", "busybox-top") _, err := cs.StartContainer("top", "busybox-top")
t.Assert(err, checker.Equals, nil) 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")
}
}
}