1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add tests for docker events -f container.

Signed-off-by: Lei Jitang <leijitang@huawei.com>
(cherry picked from commit 531ecf59f5bd92b12d4548617ca7bf179c8179a3)
This commit is contained in:
Lei Jitang 2015-12-07 08:33:16 -05:00 committed by David Calavera
parent 83a194e2dd
commit 687ef00562

View file

@ -114,3 +114,48 @@ func (s *DockerSuite) TestEventsOOMDisableTrue(c *check.C) {
c.Assert(strings.TrimSpace(out), checker.Equals, "running", check.Commentf("container should be still running"))
}
}
// #18453
func (s *DockerSuite) TestEventsContainerFilter(c *check.C) {
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top")
c1 := strings.TrimSpace(out)
waitRun(c1)
out, _ = dockerCmd(c, "run", "--name=bar", "-d", "busybox", "top")
c2 := strings.TrimSpace(out)
waitRun(c2)
out, _ = dockerCmd(c, "events", "-f", "container=foo", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
c.Assert(out, checker.Contains, c1, check.Commentf("Missing event of container (foo)"))
c.Assert(out, checker.Not(checker.Contains), c2, check.Commentf("Should not contain event of container (bar)"))
}
// #18453
func (s *DockerSuite) TestEventsContainerFilterBeforeCreate(c *check.C) {
testRequires(c, DaemonIsLinux)
var (
out string
ch chan struct{}
)
ch = make(chan struct{})
// calculate the time it takes to create and start a container and sleep 2 seconds
// this is to make sure the docker event will recevie the event of container
since := daemonTime(c).Unix()
id, _ := dockerCmd(c, "run", "-d", "busybox", "top")
cID := strings.TrimSpace(id)
waitRun(cID)
time.Sleep(2 * time.Second)
duration := daemonTime(c).Unix() - since
go func() {
out, _ = dockerCmd(c, "events", "-f", "container=foo", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()+2*duration))
close(ch)
}()
// Sleep 2 second to wait docker event to start
time.Sleep(2 * time.Second)
id, _ = dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top")
cID = strings.TrimSpace(id)
waitRun(cID)
<-ch
c.Assert(out, checker.Contains, cID, check.Commentf("Missing event of container (foo)"))
}