Make TestLogsAPIStdout a bit less racey

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2017-05-19 10:17:26 -04:00
parent 815e8bb885
commit 960b8d9294

View file

@ -19,34 +19,31 @@ func (s *DockerSuite) TestLogsAPIWithStdout(c *check.C) {
type logOut struct {
out string
res *http.Response
err error
}
chLog := make(chan logOut)
res, body, err := request.Get(fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&timestamps=1", id))
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
go func() {
res, body, err := request.Get(fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&timestamps=1", id))
if err != nil {
chLog <- logOut{"", nil, err}
return
}
defer body.Close()
out, err := bufio.NewReader(body).ReadString('\n')
if err != nil {
chLog <- logOut{"", nil, err}
chLog <- logOut{"", err}
return
}
chLog <- logOut{strings.TrimSpace(out), res, err}
chLog <- logOut{strings.TrimSpace(out), err}
}()
select {
case l := <-chLog:
c.Assert(l.err, checker.IsNil)
c.Assert(l.res.StatusCode, checker.Equals, http.StatusOK)
if !strings.HasSuffix(l.out, "hello") {
c.Fatalf("expected log output to container 'hello', but it does not")
}
case <-time.After(20 * time.Second):
case <-time.After(30 * time.Second):
c.Fatal("timeout waiting for logs to exit")
}
}