Browse code

Make TestLogsAPIStdout a bit less racey

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2017/05/19 23:17:26
Showing 1 changed files
... ...
@@ -19,34 +19,31 @@ func (s *DockerSuite) TestLogsAPIWithStdout(c *check.C) {
19 19
 
20 20
 	type logOut struct {
21 21
 		out string
22
-		res *http.Response
23 22
 		err error
24 23
 	}
24
+
25 25
 	chLog := make(chan logOut)
26
+	res, body, err := request.Get(fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&timestamps=1", id))
27
+	c.Assert(err, checker.IsNil)
28
+	c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
26 29
 
27 30
 	go func() {
28
-		res, body, err := request.Get(fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&timestamps=1", id))
29
-		if err != nil {
30
-			chLog <- logOut{"", nil, err}
31
-			return
32
-		}
33 31
 		defer body.Close()
34 32
 		out, err := bufio.NewReader(body).ReadString('\n')
35 33
 		if err != nil {
36
-			chLog <- logOut{"", nil, err}
34
+			chLog <- logOut{"", err}
37 35
 			return
38 36
 		}
39
-		chLog <- logOut{strings.TrimSpace(out), res, err}
37
+		chLog <- logOut{strings.TrimSpace(out), err}
40 38
 	}()
41 39
 
42 40
 	select {
43 41
 	case l := <-chLog:
44 42
 		c.Assert(l.err, checker.IsNil)
45
-		c.Assert(l.res.StatusCode, checker.Equals, http.StatusOK)
46 43
 		if !strings.HasSuffix(l.out, "hello") {
47 44
 			c.Fatalf("expected log output to container 'hello', but it does not")
48 45
 		}
49
-	case <-time.After(20 * time.Second):
46
+	case <-time.After(30 * time.Second):
50 47
 		c.Fatal("timeout waiting for logs to exit")
51 48
 	}
52 49
 }