Browse code

improve TestServiceLogs for the goroutine issue #28915

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>

Akihiro Suda authored on 2016/11/30 14:48:44
Showing 1 changed files
... ...
@@ -23,19 +23,29 @@ func (s *DockerSwarmSuite) TestServiceLogs(c *check.C) {
23 23
 
24 24
 	d := s.AddDaemon(c, true, true)
25 25
 
26
-	name := "TestServiceLogs"
26
+	// we have multiple services here for detecting the goroutine issue #28915
27
+	services := map[string]string{
28
+		"TestServiceLogs1": "hello1",
29
+		"TestServiceLogs2": "hello2",
30
+	}
27 31
 
28
-	out, err := d.Cmd("service", "create", "--name", name, "--restart-condition", "none", "busybox", "sh", "-c", "echo hello world")
29
-	c.Assert(err, checker.IsNil)
30
-	c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
32
+	for name, message := range services {
33
+		out, err := d.Cmd("service", "create", "--name", name, "busybox",
34
+			"sh", "-c", fmt.Sprintf("echo %s; tail -f /dev/null", message))
35
+		c.Assert(err, checker.IsNil)
36
+		c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
37
+	}
31 38
 
32 39
 	// make sure task has been deployed.
33
-	waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1)
34
-
35
-	out, err = d.Cmd("service", "logs", name)
36
-	fmt.Println(out)
37
-	c.Assert(err, checker.IsNil)
38
-	c.Assert(out, checker.Contains, "hello world")
40
+	waitAndAssert(c, defaultReconciliationTimeout,
41
+		d.checkActiveContainerCount, checker.Equals, len(services))
42
+
43
+	for name, message := range services {
44
+		out, err := d.Cmd("service", "logs", name)
45
+		c.Assert(err, checker.IsNil)
46
+		c.Logf("log for %q: %q", name, out)
47
+		c.Assert(out, checker.Contains, message)
48
+	}
39 49
 }
40 50
 
41 51
 func (s *DockerSwarmSuite) TestServiceLogsFollow(c *check.C) {