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