Merge pull request #167 from mlaventure/containers-life-events-test
Containers life events test
This commit is contained in:
commit
5b0a213766
4 changed files with 60 additions and 4 deletions
5
Makefile
5
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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue