From 0228e25fa4f067590515a59886ca5a071b59818a Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Mon, 28 Mar 2016 16:42:50 -0700 Subject: [PATCH] Add test for the kill/signal operations Signed-off-by: Kenfe-Mickael Laventure --- integration-test/start_test.go | 91 ++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/integration-test/start_test.go b/integration-test/start_test.go index 5303499..1733444 100644 --- a/integration-test/start_test.go +++ b/integration-test/start_test.go @@ -2,6 +2,7 @@ package main import ( "path/filepath" + "syscall" "time" "github.com/docker/containerd/api/grpc/types" @@ -134,3 +135,93 @@ func (cs *ContainerdSuite) TestStartBusyboxSleep(t *check.C) { t.Fatal("Container took more than 6 seconds to exit") } } + +func (cs *ContainerdSuite) TestStartBusyboxTopKill(t *check.C) { + bundleName := "busybox-top" + if err := CreateBusyboxBundle(bundleName, []string{"top"}); err != nil { + t.Fatal(err) + } + + containerId := "top" + c, err := cs.StartContainer("top", bundleName) + if err != nil { + t.Fatal(err) + } + + <-time.After(1 * time.Second) + + err = cs.KillContainer(containerId) + if err != nil { + t.Fatal(err) + } + + for _, evt := range []types.Event{ + { + Type: "start-container", + Id: containerId, + Status: 0, + Pid: "", + }, + { + Type: "exit", + Id: containerId, + Status: 128 + uint32(syscall.SIGKILL), + 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") + } + } +} + +func (cs *ContainerdSuite) TestStartBusyboxTopSignalSigterm(t *check.C) { + bundleName := "busybox-top" + if err := CreateBusyboxBundle(bundleName, []string{"top"}); err != nil { + t.Fatal(err) + } + + containerId := "top" + c, err := cs.StartContainer("top", bundleName) + if err != nil { + t.Fatal(err) + } + + <-time.After(1 * time.Second) + + err = cs.SignalContainer(containerId, uint32(syscall.SIGTERM)) + if err != nil { + t.Fatal(err) + } + + for _, evt := range []types.Event{ + { + Type: "start-container", + Id: containerId, + Status: 0, + Pid: "", + }, + { + Type: "exit", + Id: containerId, + Status: 128 + uint32(syscall.SIGTERM), + 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") + } + } +}