Add test for the kill/signal operations

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure 2016-03-28 16:42:50 -07:00
parent 2f7c21ed5b
commit 0228e25fa4

View file

@ -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")
}
}
}