From 9455c01bc45e8d52f9436a4fcda4f2d8962174bf Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Mon, 28 Mar 2016 16:23:41 -0700 Subject: [PATCH] Add a test checking container life duration Signed-off-by: Kenfe-Mickael Laventure --- integration-test/start_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/integration-test/start_test.go b/integration-test/start_test.go index db4f81f..5972a7d 100644 --- a/integration-test/start_test.go +++ b/integration-test/start_test.go @@ -96,3 +96,30 @@ func (cs *ContainerdSuite) TestStartBusyboxLsEvents(t *check.C) { } } } + +func (cs *ContainerdSuite) TestStartBusyboxSleep(t *check.C) { + if err := CreateBusyboxBundle("busybox-sleep-5", []string{"sleep", "5"}); err != nil { + t.Fatal(err) + } + + ch := make(chan interface{}) + filter := func(e *types.Event) { + if e.Type == "exit" && e.Pid == "init" { + ch <- nil + } + } + + start := time.Now() + _, err := cs.StartContainerWithEventFilter("sleep5", "busybox-sleep-5", filter) + if err != nil { + t.Fatal(err) + } + + // We add a generous 20% marge of error + select { + case <-ch: + t.Assert(uint64(time.Now().Sub(start)), checker.LessOrEqualThan, uint64(6*time.Second)) + case <-time.After(6 * time.Second): + t.Fatal("Container took more than 6 seconds to exit") + } +}