From bf20f56615eb0f7218e7e07610d53551bd79ee4b Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Mon, 28 Mar 2016 10:40:33 -0700 Subject: [PATCH 1/5] Rename busybox-NoSuchFile test bundle to busybox-no-such-file Signed-off-by: Kenfe-Mickael Laventure --- integration-test/start_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-test/start_test.go b/integration-test/start_test.go index 8d1af08..161ff9f 100644 --- a/integration-test/start_test.go +++ b/integration-test/start_test.go @@ -40,11 +40,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) } From 20ee648540756617edcf1bc9e5e364749dc49ad7 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Mon, 28 Mar 2016 11:21:50 -0700 Subject: [PATCH 2/5] Add per test and suite timeout values to Makefile Signed-off-by: Kenfe-Mickael Laventure --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2248e87..4dc6b9f 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 From e6b2ed4b7f1511c9842b064e03d423f08584fa45 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Mon, 28 Mar 2016 11:25:50 -0700 Subject: [PATCH 3/5] Wait maximum 3s per container kill when tearing down a test Signed-off-by: Kenfe-Mickael Laventure --- integration-test/check_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/integration-test/check_test.go b/integration-test/check_test.go index 23508e7..a3214aa 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) + } } } From 3481996e9dca04c42a428b754aac4c2c4a5e4674 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Mon, 28 Mar 2016 11:27:12 -0700 Subject: [PATCH 4/5] Add a way to retrieve a test container event channel Signed-off-by: Kenfe-Mickael Laventure --- integration-test/container_utils_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/integration-test/container_utils_test.go b/integration-test/container_utils_test.go index b3429e3..4dff21b 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 From 90009c8a31688b6f54791fccb3e043bf448b284f Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Mon, 28 Mar 2016 11:29:55 -0700 Subject: [PATCH 5/5] Add a test checking a ls container generated events Signed-off-by: Kenfe-Mickael Laventure --- integration-test/start_test.go | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/integration-test/start_test.go b/integration-test/start_test.go index 161ff9f..db4f81f 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" ) @@ -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") + } + } +}