mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix flaky TestEventsContainerFilterBeforeCreate
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
dee3044336
commit
e372883fcd
1 changed files with 20 additions and 28 deletions
|
@ -4,6 +4,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -140,36 +141,27 @@ func (s *DockerSuite) TestEventsContainerFilterByName(c *check.C) {
|
||||||
// #18453
|
// #18453
|
||||||
func (s *DockerSuite) TestEventsContainerFilterBeforeCreate(c *check.C) {
|
func (s *DockerSuite) TestEventsContainerFilterBeforeCreate(c *check.C) {
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
var (
|
buf := &bytes.Buffer{}
|
||||||
out string
|
cmd := exec.Command(dockerBinary, "events", "-f", "container=foo", "--since=0")
|
||||||
ch chan struct{}
|
cmd.Stdout = buf
|
||||||
)
|
c.Assert(cmd.Start(), check.IsNil)
|
||||||
ch = make(chan struct{})
|
defer cmd.Wait()
|
||||||
|
defer cmd.Process.Kill()
|
||||||
|
|
||||||
// calculate the time it takes to create and start a container and sleep 2 seconds
|
// Sleep for a second to make sure we are testing the case where events are listened before container starts.
|
||||||
// this is to make sure the docker event will recevie the event of container
|
time.Sleep(time.Second)
|
||||||
since := daemonTime(c)
|
id, _ := dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top")
|
||||||
id, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
|
||||||
cID := strings.TrimSpace(id)
|
cID := strings.TrimSpace(id)
|
||||||
waitRun(cID)
|
for i := 0; ; i++ {
|
||||||
time.Sleep(2 * time.Second)
|
out := buf.String()
|
||||||
duration := daemonTime(c).Sub(since)
|
if strings.Contains(out, cID) {
|
||||||
|
break
|
||||||
go func() {
|
}
|
||||||
// start events and wait for future events to
|
if i > 30 {
|
||||||
// make sure the new container shows up even when
|
c.Fatalf("Missing event of container (foo, %v), got %q", cID, out)
|
||||||
// the event stream was created before the container.
|
}
|
||||||
t := daemonTime(c).Add(2 * duration)
|
time.Sleep(500 * time.Millisecond)
|
||||||
out, _ = dockerCmd(c, "events", "-f", "container=foo", "--since=0", "--until", parseEventTime(t))
|
}
|
||||||
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)"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestVolumeEvents(c *check.C) {
|
func (s *DockerSuite) TestVolumeEvents(c *check.C) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue