2014-03-31 22:40:39 +04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-05-07 04:09:27 +03:00
|
|
|
"encoding/json"
|
2014-03-31 22:40:39 +04:00
|
|
|
"fmt"
|
2015-05-07 04:09:27 +03:00
|
|
|
"io"
|
2014-03-31 22:40:39 +04:00
|
|
|
"os/exec"
|
2014-04-02 23:26:06 +04:00
|
|
|
"regexp"
|
2015-04-14 07:36:12 +03:00
|
|
|
"strconv"
|
2014-04-02 23:26:06 +04:00
|
|
|
"strings"
|
|
|
|
"time"
|
2014-09-10 23:36:01 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2014-09-15 22:44:58 +04:00
|
|
|
"github.com/docker/docker/pkg/timeutils"
|
2015-04-18 19:46:47 +03:00
|
|
|
"github.com/go-check/check"
|
2014-03-31 22:40:39 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
// This used to work, it test a log of PageSize-1 (gh#4851)
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestLogsContainerSmallerThanPage(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-03-31 22:40:39 +04:00
|
|
|
testLen := 32767
|
2015-07-20 09:44:22 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen))
|
2014-03-31 22:40:39 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
dockerCmd(c, "wait", id)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "logs", id)
|
|
|
|
|
|
|
|
c.Assert(out, checker.HasLen, testLen+1)
|
2014-03-31 22:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Regression test: When going over the PageSize, it used to panic (gh#4851)
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestLogsContainerBiggerThanPage(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-03-31 22:40:39 +04:00
|
|
|
testLen := 32768
|
2015-07-20 09:44:22 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen))
|
2014-03-31 22:40:39 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
dockerCmd(c, "wait", id)
|
2014-03-31 22:40:39 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
out, _ = dockerCmd(c, "logs", id)
|
2014-03-31 22:40:39 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(out, checker.HasLen, testLen+1)
|
2014-03-31 22:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Regression test: When going much over the PageSize, it used to block (gh#4851)
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestLogsContainerMuchBiggerThanPage(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-03-31 22:40:39 +04:00
|
|
|
testLen := 33000
|
2015-07-20 09:44:22 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen))
|
2014-03-31 22:40:39 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
dockerCmd(c, "wait", id)
|
2014-03-31 22:40:39 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
out, _ = dockerCmd(c, "logs", id)
|
2014-03-31 22:40:39 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(out, checker.HasLen, testLen+1)
|
2014-03-31 22:40:39 +04:00
|
|
|
}
|
2014-04-02 23:26:06 +04:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestLogsTimestamps(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-04-02 23:26:06 +04:00
|
|
|
testLen := 100
|
2015-07-20 09:44:22 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen))
|
2014-04-02 23:26:06 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
dockerCmd(c, "wait", id)
|
2014-04-02 23:26:06 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
out, _ = dockerCmd(c, "logs", "-t", id)
|
2014-04-02 23:26:06 +04:00
|
|
|
|
|
|
|
lines := strings.Split(out, "\n")
|
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(lines, checker.HasLen, testLen+1)
|
2014-04-02 23:26:06 +04:00
|
|
|
|
2014-05-10 20:51:16 +04:00
|
|
|
ts := regexp.MustCompile(`^.* `)
|
2014-04-02 23:26:06 +04:00
|
|
|
|
|
|
|
for _, l := range lines {
|
|
|
|
if l != "" {
|
2014-09-15 22:44:58 +04:00
|
|
|
_, err := time.Parse(timeutils.RFC3339NanoFixed+" ", ts.FindString(l))
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("Failed to parse timestamp from %v", l))
|
|
|
|
// ensure we have padded 0's
|
|
|
|
c.Assert(l[29], checker.Equals, uint8('Z'))
|
2014-04-02 23:26:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestLogsSeparateStderr(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-04-02 23:26:06 +04:00
|
|
|
msg := "stderr_log"
|
2015-07-20 09:44:22 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg))
|
2014-04-02 23:26:06 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
dockerCmd(c, "wait", id)
|
2014-04-02 23:26:06 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
stdout, stderr, _ := dockerCmdWithStdoutStderr(c, "logs", id)
|
2014-04-02 23:26:06 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(stdout, checker.Equals, "")
|
2014-04-02 23:26:06 +04:00
|
|
|
|
|
|
|
stderr = strings.TrimSpace(stderr)
|
2015-10-13 04:50:17 +03:00
|
|
|
|
|
|
|
c.Assert(stderr, checker.Equals, msg)
|
2014-04-02 23:26:06 +04:00
|
|
|
}
|
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestLogsStderrInStdout(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-04-02 23:26:06 +04:00
|
|
|
msg := "stderr_log"
|
2015-07-20 09:44:22 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg))
|
2014-04-02 23:26:06 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
dockerCmd(c, "wait", id)
|
2014-04-02 23:26:06 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
stdout, stderr, _ := dockerCmdWithStdoutStderr(c, "logs", id)
|
|
|
|
c.Assert(stderr, checker.Equals, "")
|
2014-04-02 23:26:06 +04:00
|
|
|
|
|
|
|
stdout = strings.TrimSpace(stdout)
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(stdout, checker.Equals, msg)
|
2014-04-02 23:26:06 +04:00
|
|
|
}
|
2014-06-03 15:09:33 +04:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestLogsTail(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-06-03 15:09:33 +04:00
|
|
|
testLen := 100
|
2015-07-20 09:44:22 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen))
|
2014-06-03 15:09:33 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
dockerCmd(c, "wait", id)
|
2014-06-03 15:09:33 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
out, _ = dockerCmd(c, "logs", "--tail", "5", id)
|
2014-06-03 15:09:33 +04:00
|
|
|
|
|
|
|
lines := strings.Split(out, "\n")
|
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(lines, checker.HasLen, 6)
|
|
|
|
|
|
|
|
out, _ = dockerCmd(c, "logs", "--tail", "all", id)
|
2014-06-03 15:09:33 +04:00
|
|
|
|
|
|
|
lines = strings.Split(out, "\n")
|
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(lines, checker.HasLen, testLen+1)
|
|
|
|
|
|
|
|
out, _, _ = dockerCmdWithStdoutStderr(c, "logs", "--tail", "random", id)
|
2014-06-03 15:09:33 +04:00
|
|
|
|
|
|
|
lines = strings.Split(out, "\n")
|
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(lines, checker.HasLen, testLen+1)
|
2014-06-03 15:09:33 +04:00
|
|
|
}
|
2014-08-20 20:02:56 +04:00
|
|
|
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestLogsFollowStopped(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-20 09:44:22 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", "hello")
|
2014-08-20 20:02:56 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
dockerCmd(c, "wait", id)
|
2014-08-20 20:02:56 +04:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
logsCmd := exec.Command(dockerBinary, "logs", "-f", id)
|
|
|
|
c.Assert(logsCmd.Start(), checker.IsNil)
|
2014-08-20 20:02:56 +04:00
|
|
|
|
2015-04-27 20:29:48 +03:00
|
|
|
errChan := make(chan error)
|
2014-08-20 20:02:56 +04:00
|
|
|
go func() {
|
2015-04-27 20:29:48 +03:00
|
|
|
errChan <- logsCmd.Wait()
|
|
|
|
close(errChan)
|
2014-08-20 20:02:56 +04:00
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
2015-04-27 20:29:48 +03:00
|
|
|
case err := <-errChan:
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
2014-08-20 20:02:56 +04:00
|
|
|
case <-time.After(1 * time.Second):
|
2015-04-18 19:46:47 +03:00
|
|
|
c.Fatal("Following logs is hanged")
|
2014-08-20 20:02:56 +04:00
|
|
|
}
|
|
|
|
}
|
2014-10-30 22:33:26 +03:00
|
|
|
|
2015-04-14 07:36:12 +03:00
|
|
|
func (s *DockerSuite) TestLogsSince(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-14 07:36:12 +03:00
|
|
|
name := "testlogssince"
|
2015-07-20 09:44:22 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "--name="+name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do sleep 2; echo `date +%s` log$i; done")
|
2015-04-14 07:36:12 +03:00
|
|
|
|
2015-05-13 05:49:47 +03:00
|
|
|
log2Line := strings.Split(strings.Split(out, "\n")[1], " ")
|
2015-08-08 01:24:18 +03:00
|
|
|
t, err := strconv.ParseInt(log2Line[0], 10, 64) // the timestamp log2 is written
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-13 05:49:47 +03:00
|
|
|
since := t + 1 // add 1s so log1 & log2 doesn't show up
|
2015-07-20 09:44:22 +03:00
|
|
|
out, _ = dockerCmd(c, "logs", "-t", fmt.Sprintf("--since=%v", since), name)
|
2015-04-14 07:36:12 +03:00
|
|
|
|
|
|
|
// Skip 2 seconds
|
|
|
|
unexpected := []string{"log1", "log2"}
|
|
|
|
for _, v := range unexpected {
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(out, checker.Not(checker.Contains), v, check.Commentf("unexpected log message returned, since=%v", since))
|
2015-04-14 07:36:12 +03:00
|
|
|
}
|
|
|
|
// Test with default value specified and parameter omitted
|
2015-05-13 05:49:47 +03:00
|
|
|
expected := []string{"log1", "log2", "log3"}
|
2015-04-14 07:36:12 +03:00
|
|
|
for _, cmd := range []*exec.Cmd{
|
|
|
|
exec.Command(dockerBinary, "logs", "-t", name),
|
|
|
|
exec.Command(dockerBinary, "logs", "-t", "--since=0", name),
|
|
|
|
} {
|
|
|
|
out, _, err = runCommandWithOutput(cmd)
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to log container: %s", out))
|
2015-04-14 07:36:12 +03:00
|
|
|
for _, v := range expected {
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(out, checker.Contains, v)
|
2015-04-14 07:36:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestLogsSinceFutureFollow(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-20 09:44:22 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", `for i in $(seq 1 5); do date +%s; sleep 1; done`)
|
2015-10-13 04:50:17 +03:00
|
|
|
id := strings.TrimSpace(out)
|
2015-04-14 07:36:12 +03:00
|
|
|
|
|
|
|
now := daemonTime(c).Unix()
|
|
|
|
since := now + 2
|
2015-10-13 04:50:17 +03:00
|
|
|
out, _ = dockerCmd(c, "logs", "-f", fmt.Sprintf("--since=%v", since), id)
|
2015-04-14 07:36:12 +03:00
|
|
|
lines := strings.Split(strings.TrimSpace(out), "\n")
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(lines, checker.Not(checker.HasLen), 0)
|
2015-04-14 07:36:12 +03:00
|
|
|
for _, v := range lines {
|
|
|
|
ts, err := strconv.ParseInt(v, 10, 64)
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("cannot parse timestamp output from log: '%v'\nout=%s", v, out))
|
|
|
|
c.Assert(ts >= since, checker.Equals, true, check.Commentf("earlier log found. since=%v logdate=%v", since, ts))
|
2015-04-14 07:36:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-30 22:33:26 +03:00
|
|
|
// Regression test for #8832
|
2015-04-18 19:46:47 +03:00
|
|
|
func (s *DockerSuite) TestLogsFollowSlowStdoutConsumer(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-20 09:44:22 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", `usleep 200000;yes X | head -c 200000`)
|
2014-10-30 22:33:26 +03:00
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
id := strings.TrimSpace(out)
|
2014-10-30 22:33:26 +03:00
|
|
|
|
|
|
|
stopSlowRead := make(chan bool)
|
|
|
|
|
|
|
|
go func() {
|
2015-10-13 04:50:17 +03:00
|
|
|
exec.Command(dockerBinary, "wait", id).Run()
|
2014-10-30 22:33:26 +03:00
|
|
|
stopSlowRead <- true
|
|
|
|
}()
|
|
|
|
|
2015-10-13 04:50:17 +03:00
|
|
|
logCmd := exec.Command(dockerBinary, "logs", "-f", id)
|
2014-10-30 22:33:26 +03:00
|
|
|
stdout, err := logCmd.StdoutPipe()
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(logCmd.Start(), checker.IsNil)
|
2014-10-30 22:33:26 +03:00
|
|
|
|
|
|
|
// First read slowly
|
|
|
|
bytes1, err := consumeWithSpeed(stdout, 10, 50*time.Millisecond, stopSlowRead)
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
2014-10-30 22:33:26 +03:00
|
|
|
|
|
|
|
// After the container has finished we can continue reading fast
|
|
|
|
bytes2, err := consumeWithSpeed(stdout, 32*1024, 0, nil)
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
2014-10-30 22:33:26 +03:00
|
|
|
|
|
|
|
actual := bytes1 + bytes2
|
|
|
|
expected := 200000
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(actual, checker.Equals, expected)
|
2014-10-30 22:33:26 +03:00
|
|
|
|
|
|
|
}
|
2015-05-07 04:09:27 +03:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-05-07 04:09:27 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 2; done")
|
|
|
|
id := strings.TrimSpace(out)
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(waitRun(id), checker.IsNil)
|
2015-05-07 04:09:27 +03:00
|
|
|
|
|
|
|
type info struct {
|
|
|
|
NGoroutines int
|
|
|
|
}
|
|
|
|
getNGoroutines := func() int {
|
|
|
|
var i info
|
|
|
|
status, b, err := sockRequest("GET", "/info", nil)
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, 200)
|
|
|
|
c.Assert(json.Unmarshal(b, &i), checker.IsNil)
|
2015-05-07 04:09:27 +03:00
|
|
|
return i.NGoroutines
|
|
|
|
}
|
|
|
|
|
|
|
|
nroutines := getNGoroutines()
|
|
|
|
|
|
|
|
cmd := exec.Command(dockerBinary, "logs", "-f", id)
|
|
|
|
r, w := io.Pipe()
|
|
|
|
cmd.Stdout = w
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(cmd.Start(), checker.IsNil)
|
2015-05-07 04:09:27 +03:00
|
|
|
|
|
|
|
// Make sure pipe is written to
|
|
|
|
chErr := make(chan error)
|
|
|
|
go func() {
|
|
|
|
b := make([]byte, 1)
|
|
|
|
_, err := r.Read(b)
|
|
|
|
chErr <- err
|
|
|
|
}()
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(<-chErr, checker.IsNil)
|
|
|
|
c.Assert(cmd.Process.Kill(), checker.IsNil)
|
2015-05-07 04:09:27 +03:00
|
|
|
|
|
|
|
// NGoroutines is not updated right away, so we need to wait before failing
|
2015-05-15 16:54:43 +03:00
|
|
|
t := time.After(30 * time.Second)
|
2015-05-07 04:09:27 +03:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-t:
|
2015-10-13 04:50:17 +03:00
|
|
|
n := getNGoroutines()
|
|
|
|
c.Assert(n <= nroutines, checker.Equals, true, check.Commentf("leaked goroutines: expected less than or equal to %d, got: %d", nroutines, n))
|
|
|
|
|
2015-05-07 04:09:27 +03:00
|
|
|
default:
|
2015-05-21 20:02:16 +03:00
|
|
|
if n := getNGoroutines(); n <= nroutines {
|
2015-05-07 04:09:27 +03:00
|
|
|
return
|
|
|
|
}
|
2015-05-15 16:54:43 +03:00
|
|
|
time.Sleep(200 * time.Millisecond)
|
2015-05-07 04:09:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-04 22:15:33 +03:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestLogsFollowGoroutinesNoOutput(c *check.C) {
|
2015-08-28 20:36:42 +03:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-06-04 22:15:33 +03:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "while true; do sleep 2; done")
|
|
|
|
id := strings.TrimSpace(out)
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(waitRun(id), checker.IsNil)
|
2015-06-04 22:15:33 +03:00
|
|
|
|
|
|
|
type info struct {
|
|
|
|
NGoroutines int
|
|
|
|
}
|
|
|
|
getNGoroutines := func() int {
|
|
|
|
var i info
|
|
|
|
status, b, err := sockRequest("GET", "/info", nil)
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(status, checker.Equals, 200)
|
|
|
|
c.Assert(json.Unmarshal(b, &i), checker.IsNil)
|
2015-06-04 22:15:33 +03:00
|
|
|
return i.NGoroutines
|
|
|
|
}
|
|
|
|
|
|
|
|
nroutines := getNGoroutines()
|
|
|
|
|
|
|
|
cmd := exec.Command(dockerBinary, "logs", "-f", id)
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(cmd.Start(), checker.IsNil)
|
2015-06-04 22:15:33 +03:00
|
|
|
time.Sleep(200 * time.Millisecond)
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(cmd.Process.Kill(), checker.IsNil)
|
2015-06-04 22:15:33 +03:00
|
|
|
|
|
|
|
// NGoroutines is not updated right away, so we need to wait before failing
|
|
|
|
t := time.After(30 * time.Second)
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-t:
|
2015-10-13 04:50:17 +03:00
|
|
|
n := getNGoroutines()
|
|
|
|
c.Assert(n <= nroutines, checker.Equals, true, check.Commentf("leaked goroutines: expected less than or equal to %d, got: %d", nroutines, n))
|
|
|
|
|
2015-06-04 22:15:33 +03:00
|
|
|
default:
|
|
|
|
if n := getNGoroutines(); n <= nroutines {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-28 23:36:29 +03:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestLogsCLIContainerNotFound(c *check.C) {
|
|
|
|
name := "testlogsnocontainer"
|
|
|
|
out, _, _ := dockerCmdWithError("logs", name)
|
|
|
|
message := fmt.Sprintf(".*no such id: %s.*\n", name)
|
2015-10-13 04:50:17 +03:00
|
|
|
c.Assert(out, checker.Matches, message)
|
2015-09-28 23:36:29 +03:00
|
|
|
}
|