2014-03-31 14:40:39 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2014-09-10 15:36:01 -04:00
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2017-03-27 11:12:48 -04:00
|
|
|
"github.com/docker/docker/integration-cli/cli"
|
2015-12-15 14:49:41 -05:00
|
|
|
"github.com/docker/docker/pkg/jsonlog"
|
2017-01-05 13:08:24 -05:00
|
|
|
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
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) {
|
2017-01-02 17:42:45 -05:00
|
|
|
testLogsContainerPagination(c, 32767)
|
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) {
|
2017-01-02 17:42:45 -05:00
|
|
|
testLogsContainerPagination(c, 32768)
|
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) {
|
2017-01-02 17:42:45 -05:00
|
|
|
testLogsContainerPagination(c, 33000)
|
|
|
|
}
|
2014-03-31 14:40:39 -04:00
|
|
|
|
2017-01-02 17:42:45 -05:00
|
|
|
func testLogsContainerPagination(c *check.C, testLen int) {
|
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n = >> a.a; done; echo >> a.a; cat a.a", testLen))
|
2015-10-12 21:50:17 -04:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
dockerCmd(c, "wait", id)
|
|
|
|
out, _ = dockerCmd(c, "logs", id)
|
|
|
|
c.Assert(out, checker.HasLen, testLen+1)
|
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
|
2016-03-12 19:15:14 -05:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo = >> a.a; done; cat a.a", testLen))
|
2014-04-02 15:26:06 -04:00
|
|
|
|
2015-10-12 21:50:17 -04:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
dockerCmd(c, "wait", id)
|
2014-04-02 15:26:06 -04:00
|
|
|
|
2015-10-12 21:50:17 -04:00
|
|
|
out, _ = dockerCmd(c, "logs", "-t", id)
|
2014-04-02 15:26:06 -04:00
|
|
|
|
|
|
|
lines := strings.Split(out, "\n")
|
|
|
|
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(lines, checker.HasLen, testLen+1)
|
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 != "" {
|
2015-12-15 14:49:41 -05:00
|
|
|
_, err := time.Parse(jsonlog.RFC3339NanoFixed+" ", ts.FindString(l))
|
2015-10-12 21:50:17 -04: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 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"
|
2017-03-27 11:12:48 -04:00
|
|
|
out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg)).Combined()
|
2015-10-12 21:50:17 -04:00
|
|
|
id := strings.TrimSpace(out)
|
2017-03-27 11:12:48 -04:00
|
|
|
cli.DockerCmd(c, "wait", id)
|
|
|
|
cli.DockerCmd(c, "logs", id).Assert(c, icmd.Expected{
|
|
|
|
Out: "",
|
|
|
|
Err: msg,
|
|
|
|
})
|
2014-04-02 15:26:06 -04:00
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLogsStderrInStdout(c *check.C) {
|
2016-02-24 17:26:08 -05:00
|
|
|
// TODO Windows: Needs investigation why this fails. Obtained string includes
|
|
|
|
// a bunch of ANSI escape sequences before the "stderr_log" message.
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-04-02 15:26:06 -04:00
|
|
|
msg := "stderr_log"
|
2017-03-27 11:12:48 -04:00
|
|
|
out := cli.DockerCmd(c, "run", "-d", "-t", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg)).Combined()
|
2015-10-12 21:50:17 -04:00
|
|
|
id := strings.TrimSpace(out)
|
2017-03-27 11:12:48 -04:00
|
|
|
cli.DockerCmd(c, "wait", id)
|
2014-04-02 15:26:06 -04:00
|
|
|
|
2017-03-27 11:12:48 -04:00
|
|
|
cli.DockerCmd(c, "logs", id).Assert(c, icmd.Expected{
|
|
|
|
Out: msg,
|
|
|
|
Err: "",
|
|
|
|
})
|
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
|
2017-03-27 11:12:48 -04:00
|
|
|
out := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen)).Combined()
|
2014-06-03 07:09:33 -04:00
|
|
|
|
2015-10-12 21:50:17 -04:00
|
|
|
id := strings.TrimSpace(out)
|
2017-03-27 11:12:48 -04:00
|
|
|
cli.DockerCmd(c, "wait", id)
|
2014-06-03 07:09:33 -04:00
|
|
|
|
2017-03-27 11:12:48 -04:00
|
|
|
out = cli.DockerCmd(c, "logs", "--tail", "0", id).Combined()
|
2014-06-03 07:09:33 -04:00
|
|
|
lines := strings.Split(out, "\n")
|
2016-11-09 22:16:47 -05:00
|
|
|
c.Assert(lines, checker.HasLen, 1)
|
2014-06-03 07:09:33 -04:00
|
|
|
|
2017-03-27 11:12:48 -04:00
|
|
|
out = cli.DockerCmd(c, "logs", "--tail", "5", id).Combined()
|
2016-11-09 22:16:47 -05:00
|
|
|
lines = strings.Split(out, "\n")
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(lines, checker.HasLen, 6)
|
|
|
|
|
2017-03-27 11:12:48 -04:00
|
|
|
out = cli.DockerCmd(c, "logs", "--tail", "99", id).Combined()
|
2016-11-09 22:16:47 -05:00
|
|
|
lines = strings.Split(out, "\n")
|
|
|
|
c.Assert(lines, checker.HasLen, 100)
|
2014-06-03 07:09:33 -04:00
|
|
|
|
2017-03-27 11:12:48 -04:00
|
|
|
out = cli.DockerCmd(c, "logs", "--tail", "all", id).Combined()
|
2014-06-03 07:09:33 -04:00
|
|
|
lines = strings.Split(out, "\n")
|
2016-11-09 22:16:47 -05:00
|
|
|
c.Assert(lines, checker.HasLen, testLen+1)
|
2014-06-03 07:09:33 -04:00
|
|
|
|
2017-03-27 11:12:48 -04:00
|
|
|
out = cli.DockerCmd(c, "logs", "--tail", "-1", id).Combined()
|
2016-11-09 22:16:47 -05:00
|
|
|
lines = strings.Split(out, "\n")
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(lines, checker.HasLen, testLen+1)
|
|
|
|
|
2017-03-27 11:12:48 -04:00
|
|
|
out = cli.DockerCmd(c, "logs", "--tail", "random", id).Combined()
|
2014-06-03 07:09:33 -04:00
|
|
|
lines = strings.Split(out, "\n")
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(lines, checker.HasLen, testLen+1)
|
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) {
|
2016-02-28 05:47:37 -05:00
|
|
|
dockerCmd(c, "run", "--name=test", "busybox", "echo", "hello")
|
2017-01-16 05:30:14 -05:00
|
|
|
id := getIDByName(c, "test")
|
2014-08-20 12:02:56 -04:00
|
|
|
|
2015-10-12 21:50:17 -04:00
|
|
|
logsCmd := exec.Command(dockerBinary, "logs", "-f", id)
|
|
|
|
c.Assert(logsCmd.Start(), checker.IsNil)
|
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:
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-02-24 17:26:08 -05:00
|
|
|
case <-time.After(30 * 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-12-07 16:26:30 -05:00
|
|
|
dockerCmd(c, "run", "--name="+name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do sleep 2; echo log$i; done")
|
|
|
|
out, _ := dockerCmd(c, "logs", "-t", name)
|
2015-04-14 00:36:12 -04:00
|
|
|
|
2015-05-12 22:49:47 -04:00
|
|
|
log2Line := strings.Split(strings.Split(out, "\n")[1], " ")
|
2015-12-07 16:26:30 -05:00
|
|
|
t, err := time.Parse(time.RFC3339Nano, log2Line[0]) // the timestamp log2 is written
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-12-07 16:26:30 -05:00
|
|
|
since := t.Unix() + 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 {
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(out, checker.Not(checker.Contains), v, check.Commentf("unexpected log message returned, since=%v", since))
|
2015-04-14 00:36:12 -04:00
|
|
|
}
|
2015-10-29 13:51:36 -04:00
|
|
|
|
|
|
|
// Test to make sure a bad since format is caught by the client
|
|
|
|
out, _, _ = dockerCmdWithError("logs", "-t", "--since=2006-01-02T15:04:0Z", name)
|
|
|
|
c.Assert(out, checker.Contains, "cannot parse \"0Z\" as \"05\"", check.Commentf("bad since format passed to server"))
|
|
|
|
|
2015-04-14 00:36:12 -04:00
|
|
|
// Test with default value specified and parameter omitted
|
2015-05-12 22:49:47 -04:00
|
|
|
expected := []string{"log1", "log2", "log3"}
|
2017-01-05 06:38:34 -05:00
|
|
|
for _, cmd := range [][]string{
|
2017-01-05 13:08:24 -05:00
|
|
|
{"logs", "-t", name},
|
|
|
|
{"logs", "-t", "--since=0", name},
|
2015-04-14 00:36:12 -04:00
|
|
|
} {
|
2017-01-05 13:08:24 -05:00
|
|
|
result := icmd.RunCommand(dockerBinary, cmd...)
|
2017-01-05 06:38:34 -05:00
|
|
|
result.Assert(c, icmd.Success)
|
2015-04-14 00:36:12 -04:00
|
|
|
for _, v := range expected {
|
2017-01-05 06:38:34 -05:00
|
|
|
c.Assert(result.Combined(), checker.Contains, v)
|
2015-04-14 00:36:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestLogsSinceFutureFollow(c *check.C) {
|
2016-04-12 12:39:46 -04:00
|
|
|
// TODO Windows TP5 - Figure out why this test is so flakey. Disabled for now.
|
|
|
|
testRequires(c, DaemonIsLinux)
|
2016-02-16 16:49:44 -05:00
|
|
|
name := "testlogssincefuturefollow"
|
|
|
|
out, _ := dockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", `for i in $(seq 1 5); do echo log$i; sleep 1; done`)
|
|
|
|
|
|
|
|
// Extract one timestamp from the log file to give us a starting point for
|
|
|
|
// our `--since` argument. Because the log producer runs in the background,
|
|
|
|
// we need to check repeatedly for some output to be produced.
|
|
|
|
var timestamp string
|
2016-02-24 17:26:08 -05:00
|
|
|
for i := 0; i != 100 && timestamp == ""; i++ {
|
2016-02-16 16:49:44 -05:00
|
|
|
if out, _ = dockerCmd(c, "logs", "-t", name); out == "" {
|
|
|
|
time.Sleep(time.Millisecond * 100) // Retry
|
|
|
|
} else {
|
|
|
|
timestamp = strings.Split(strings.Split(out, "\n")[0], " ")[0]
|
|
|
|
}
|
|
|
|
}
|
2015-04-14 00:36:12 -04:00
|
|
|
|
2016-02-16 16:49:44 -05:00
|
|
|
c.Assert(timestamp, checker.Not(checker.Equals), "")
|
|
|
|
t, err := time.Parse(time.RFC3339Nano, timestamp)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
since := t.Unix() + 2
|
|
|
|
out, _ = dockerCmd(c, "logs", "-t", "-f", fmt.Sprintf("--since=%v", since), name)
|
2016-03-11 15:09:00 -05:00
|
|
|
c.Assert(out, checker.Not(checker.HasLen), 0, check.Commentf("cannot read from empty log"))
|
2015-04-14 00:36:12 -04:00
|
|
|
lines := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
for _, v := range lines {
|
2016-02-16 16:49:44 -05:00
|
|
|
ts, err := time.Parse(time.RFC3339Nano, strings.Split(v, " ")[0])
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("cannot parse timestamp output from log: '%v'", v))
|
|
|
|
c.Assert(ts.Unix() >= since, checker.Equals, true, check.Commentf("earlier log found. since=%v logdate=%v", since, ts))
|
2015-04-14 00:36:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2016-04-06 17:01:12 -04:00
|
|
|
// TODO Windows: Fix this test for TP5.
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-10-26 11:46:49 -04:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", `usleep 600000;yes X | head -c 200000`)
|
2014-10-30 15:33:26 -04:00
|
|
|
|
2015-10-12 21:50:17 -04:00
|
|
|
id := strings.TrimSpace(out)
|
2014-10-30 15:33:26 -04:00
|
|
|
|
|
|
|
stopSlowRead := make(chan bool)
|
|
|
|
|
|
|
|
go func() {
|
2015-10-12 21:50:17 -04:00
|
|
|
exec.Command(dockerBinary, "wait", id).Run()
|
2014-10-30 15:33:26 -04:00
|
|
|
stopSlowRead <- true
|
|
|
|
}()
|
|
|
|
|
2015-10-12 21:50:17 -04:00
|
|
|
logCmd := exec.Command(dockerBinary, "logs", "-f", id)
|
2014-10-30 15:33:26 -04:00
|
|
|
stdout, err := logCmd.StdoutPipe()
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(logCmd.Start(), checker.IsNil)
|
2014-10-30 15:33:26 -04:00
|
|
|
|
|
|
|
// First read slowly
|
2017-08-21 18:58:25 -04:00
|
|
|
bytes1, err := ConsumeWithSpeed(stdout, 10, 50*time.Millisecond, stopSlowRead)
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2014-10-30 15:33:26 -04:00
|
|
|
|
|
|
|
// After the container has finished we can continue reading fast
|
2017-08-21 18:58:25 -04:00
|
|
|
bytes2, err := ConsumeWithSpeed(stdout, 32*1024, 0, nil)
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2014-10-30 15:33:26 -04:00
|
|
|
|
|
|
|
actual := bytes1 + bytes2
|
|
|
|
expected := 200000
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(actual, checker.Equals, expected)
|
2014-10-30 15:33:26 -04:00
|
|
|
}
|
2015-05-06 21:09:27 -04:00
|
|
|
|
2017-08-21 18:58:25 -04:00
|
|
|
// ConsumeWithSpeed reads chunkSize bytes from reader before sleeping
|
|
|
|
// for interval duration. Returns total read bytes. Send true to the
|
|
|
|
// stop channel to return before reading to EOF on the reader.
|
|
|
|
func ConsumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, stop chan bool) (n int, err error) {
|
|
|
|
buffer := make([]byte, chunkSize)
|
|
|
|
for {
|
|
|
|
var readBytes int
|
|
|
|
readBytes, err = reader.Read(buffer)
|
|
|
|
n += readBytes
|
|
|
|
if err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
case <-stop:
|
|
|
|
return
|
|
|
|
case <-time.After(interval):
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(waitRun(id), checker.IsNil)
|
2015-05-06 21:09:27 -04:00
|
|
|
|
2016-03-14 18:52:50 -04:00
|
|
|
nroutines, err := getGoroutineNumber()
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-06 21:09:27 -04:00
|
|
|
cmd := exec.Command(dockerBinary, "logs", "-f", id)
|
|
|
|
r, w := io.Pipe()
|
|
|
|
cmd.Stdout = w
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(cmd.Start(), checker.IsNil)
|
2015-05-06 21:09:27 -04: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-12 21:50:17 -04:00
|
|
|
c.Assert(<-chErr, checker.IsNil)
|
|
|
|
c.Assert(cmd.Process.Kill(), checker.IsNil)
|
2017-01-11 15:38:52 -05:00
|
|
|
r.Close()
|
2015-05-06 21:09:27 -04:00
|
|
|
// NGoroutines is not updated right away, so we need to wait before failing
|
2016-03-14 18:52:50 -04:00
|
|
|
c.Assert(waitForGoroutines(nroutines), checker.IsNil)
|
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)
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(waitRun(id), checker.IsNil)
|
2015-06-04 15:15:33 -04:00
|
|
|
|
2016-03-14 18:52:50 -04:00
|
|
|
nroutines, err := getGoroutineNumber()
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-04 15:15:33 -04:00
|
|
|
cmd := exec.Command(dockerBinary, "logs", "-f", id)
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(cmd.Start(), checker.IsNil)
|
2015-06-04 15:15:33 -04:00
|
|
|
time.Sleep(200 * time.Millisecond)
|
2015-10-12 21:50:17 -04:00
|
|
|
c.Assert(cmd.Process.Kill(), checker.IsNil)
|
2015-06-04 15:15:33 -04:00
|
|
|
|
|
|
|
// NGoroutines is not updated right away, so we need to wait before failing
|
2016-03-14 18:52:50 -04:00
|
|
|
c.Assert(waitForGoroutines(nroutines), checker.IsNil)
|
2015-06-04 15:15:33 -04:00
|
|
|
}
|
2015-09-28 16:36:29 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestLogsCLIContainerNotFound(c *check.C) {
|
|
|
|
name := "testlogsnocontainer"
|
|
|
|
out, _, _ := dockerCmdWithError("logs", name)
|
2016-11-22 08:51:22 -05:00
|
|
|
message := fmt.Sprintf("No such container: %s\n", name)
|
|
|
|
c.Assert(out, checker.Contains, message)
|
2015-09-28 16:36:29 -04:00
|
|
|
}
|
2016-04-08 12:15:08 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestLogsWithDetails(c *check.C) {
|
|
|
|
dockerCmd(c, "run", "--name=test", "--label", "foo=bar", "-e", "baz=qux", "--log-opt", "labels=foo", "--log-opt", "env=baz", "busybox", "echo", "hello")
|
|
|
|
out, _ := dockerCmd(c, "logs", "--details", "--timestamps", "test")
|
|
|
|
|
|
|
|
logFields := strings.Fields(strings.TrimSpace(out))
|
|
|
|
c.Assert(len(logFields), checker.Equals, 3, check.Commentf(out))
|
|
|
|
|
|
|
|
details := strings.Split(logFields[1], ",")
|
|
|
|
c.Assert(details, checker.HasLen, 2)
|
|
|
|
c.Assert(details[0], checker.Equals, "baz=qux")
|
|
|
|
c.Assert(details[1], checker.Equals, "foo=bar")
|
|
|
|
}
|