|
@@ -17,21 +17,11 @@ import (
|
|
|
// This used to work, it test a log of PageSize-1 (gh#4851)
|
|
|
func (s *DockerSuite) TestLogsContainerSmallerThanPage(c *check.C) {
|
|
|
testLen := 32767
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen))
|
|
|
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("run failed with errors: %s, %v", out, err)
|
|
|
- }
|
|
|
-
|
|
|
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen))
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run()
|
|
|
-
|
|
|
- logsCmd := exec.Command(dockerBinary, "logs", cleanedContainerID)
|
|
|
- out, _, _, err = runCommandWithStdoutStderr(logsCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to log container: %s, %v", out, err)
|
|
|
- }
|
|
|
|
|
|
+ dockerCmd(c, "wait", cleanedContainerID)
|
|
|
+ out, _ = dockerCmd(c, "logs", cleanedContainerID)
|
|
|
if len(out) != testLen+1 {
|
|
|
c.Fatalf("Expected log length of %d, received %d\n", testLen+1, len(out))
|
|
|
}
|
|
@@ -40,20 +30,12 @@ func (s *DockerSuite) TestLogsContainerSmallerThanPage(c *check.C) {
|
|
|
// Regression test: When going over the PageSize, it used to panic (gh#4851)
|
|
|
func (s *DockerSuite) TestLogsContainerBiggerThanPage(c *check.C) {
|
|
|
testLen := 32768
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen))
|
|
|
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("run failed with errors: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen))
|
|
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run()
|
|
|
+ dockerCmd(c, "wait", cleanedContainerID)
|
|
|
|
|
|
- logsCmd := exec.Command(dockerBinary, "logs", cleanedContainerID)
|
|
|
- out, _, _, err = runCommandWithStdoutStderr(logsCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to log container: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ = dockerCmd(c, "logs", cleanedContainerID)
|
|
|
|
|
|
if len(out) != testLen+1 {
|
|
|
c.Fatalf("Expected log length of %d, received %d\n", testLen+1, len(out))
|
|
@@ -63,20 +45,12 @@ func (s *DockerSuite) TestLogsContainerBiggerThanPage(c *check.C) {
|
|
|
// Regression test: When going much over the PageSize, it used to block (gh#4851)
|
|
|
func (s *DockerSuite) TestLogsContainerMuchBiggerThanPage(c *check.C) {
|
|
|
testLen := 33000
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen))
|
|
|
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("run failed with errors: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen))
|
|
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run()
|
|
|
+ dockerCmd(c, "wait", cleanedContainerID)
|
|
|
|
|
|
- logsCmd := exec.Command(dockerBinary, "logs", cleanedContainerID)
|
|
|
- out, _, _, err = runCommandWithStdoutStderr(logsCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to log container: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ = dockerCmd(c, "logs", cleanedContainerID)
|
|
|
|
|
|
if len(out) != testLen+1 {
|
|
|
c.Fatalf("Expected log length of %d, received %d\n", testLen+1, len(out))
|
|
@@ -85,21 +59,12 @@ func (s *DockerSuite) TestLogsContainerMuchBiggerThanPage(c *check.C) {
|
|
|
|
|
|
func (s *DockerSuite) TestLogsTimestamps(c *check.C) {
|
|
|
testLen := 100
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen))
|
|
|
-
|
|
|
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("run failed with errors: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen))
|
|
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run()
|
|
|
+ dockerCmd(c, "wait", cleanedContainerID)
|
|
|
|
|
|
- logsCmd := exec.Command(dockerBinary, "logs", "-t", cleanedContainerID)
|
|
|
- out, _, _, err = runCommandWithStdoutStderr(logsCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to log container: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ = dockerCmd(c, "logs", "-t", cleanedContainerID)
|
|
|
|
|
|
lines := strings.Split(out, "\n")
|
|
|
|
|
@@ -124,21 +89,12 @@ func (s *DockerSuite) TestLogsTimestamps(c *check.C) {
|
|
|
|
|
|
func (s *DockerSuite) TestLogsSeparateStderr(c *check.C) {
|
|
|
msg := "stderr_log"
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg))
|
|
|
-
|
|
|
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("run failed with errors: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg))
|
|
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run()
|
|
|
+ dockerCmd(c, "wait", cleanedContainerID)
|
|
|
|
|
|
- logsCmd := exec.Command(dockerBinary, "logs", cleanedContainerID)
|
|
|
- stdout, stderr, _, err := runCommandWithStdoutStderr(logsCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to log container: %s, %v", out, err)
|
|
|
- }
|
|
|
+ stdout, stderr, _ := dockerCmdWithStdoutStderr(c, "logs", cleanedContainerID)
|
|
|
|
|
|
if stdout != "" {
|
|
|
c.Fatalf("Expected empty stdout stream, got %v", stdout)
|
|
@@ -152,22 +108,12 @@ func (s *DockerSuite) TestLogsSeparateStderr(c *check.C) {
|
|
|
|
|
|
func (s *DockerSuite) TestLogsStderrInStdout(c *check.C) {
|
|
|
msg := "stderr_log"
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "-d", "-t", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg))
|
|
|
-
|
|
|
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("run failed with errors: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "sh", "-c", fmt.Sprintf("echo %s 1>&2", msg))
|
|
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run()
|
|
|
-
|
|
|
- logsCmd := exec.Command(dockerBinary, "logs", cleanedContainerID)
|
|
|
- stdout, stderr, _, err := runCommandWithStdoutStderr(logsCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to log container: %s, %v", out, err)
|
|
|
- }
|
|
|
+ dockerCmd(c, "wait", cleanedContainerID)
|
|
|
|
|
|
+ stdout, stderr, _ := dockerCmdWithStdoutStderr(c, "logs", cleanedContainerID)
|
|
|
if stderr != "" {
|
|
|
c.Fatalf("Expected empty stderr stream, got %v", stdout)
|
|
|
}
|
|
@@ -180,45 +126,26 @@ func (s *DockerSuite) TestLogsStderrInStdout(c *check.C) {
|
|
|
|
|
|
func (s *DockerSuite) TestLogsTail(c *check.C) {
|
|
|
testLen := 100
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen))
|
|
|
-
|
|
|
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("run failed with errors: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo =; done;", testLen))
|
|
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run()
|
|
|
+ dockerCmd(c, "wait", cleanedContainerID)
|
|
|
|
|
|
- logsCmd := exec.Command(dockerBinary, "logs", "--tail", "5", cleanedContainerID)
|
|
|
- out, _, _, err = runCommandWithStdoutStderr(logsCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to log container: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ = dockerCmd(c, "logs", "--tail", "5", cleanedContainerID)
|
|
|
|
|
|
lines := strings.Split(out, "\n")
|
|
|
|
|
|
if len(lines) != 6 {
|
|
|
c.Fatalf("Expected log %d lines, received %d\n", 6, len(lines))
|
|
|
}
|
|
|
-
|
|
|
- logsCmd = exec.Command(dockerBinary, "logs", "--tail", "all", cleanedContainerID)
|
|
|
- out, _, _, err = runCommandWithStdoutStderr(logsCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to log container: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ = dockerCmd(c, "logs", "--tail", "all", cleanedContainerID)
|
|
|
|
|
|
lines = strings.Split(out, "\n")
|
|
|
|
|
|
if len(lines) != testLen+1 {
|
|
|
c.Fatalf("Expected log %d lines, received %d\n", testLen+1, len(lines))
|
|
|
}
|
|
|
-
|
|
|
- logsCmd = exec.Command(dockerBinary, "logs", "--tail", "random", cleanedContainerID)
|
|
|
- out, _, _, err = runCommandWithStdoutStderr(logsCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to log container: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _, _ = dockerCmdWithStdoutStderr(c, "logs", "--tail", "random", cleanedContainerID)
|
|
|
|
|
|
lines = strings.Split(out, "\n")
|
|
|
|
|
@@ -228,15 +155,10 @@ func (s *DockerSuite) TestLogsTail(c *check.C) {
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestLogsFollowStopped(c *check.C) {
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "hello")
|
|
|
-
|
|
|
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("run failed with errors: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", "hello")
|
|
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
- exec.Command(dockerBinary, "wait", cleanedContainerID).Run()
|
|
|
+ dockerCmd(c, "wait", cleanedContainerID)
|
|
|
|
|
|
logsCmd := exec.Command(dockerBinary, "logs", "-f", cleanedContainerID)
|
|
|
if err := logsCmd.Start(); err != nil {
|
|
@@ -259,22 +181,13 @@ func (s *DockerSuite) TestLogsFollowStopped(c *check.C) {
|
|
|
|
|
|
func (s *DockerSuite) TestLogsSince(c *check.C) {
|
|
|
name := "testlogssince"
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "--name="+name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do sleep 2; echo `date +%s` log$i; done")
|
|
|
- out, _, err := runCommandWithOutput(runCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("run failed with errors: %s, %v", out, err)
|
|
|
- }
|
|
|
+ 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")
|
|
|
|
|
|
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
|
|
|
- logsCmd := exec.Command(dockerBinary, "logs", "-t", fmt.Sprintf("--since=%v", since), name)
|
|
|
-
|
|
|
- out, _, err = runCommandWithOutput(logsCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to log container: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ = dockerCmd(c, "logs", "-t", fmt.Sprintf("--since=%v", since), name)
|
|
|
|
|
|
// Skip 2 seconds
|
|
|
unexpected := []string{"log1", "log2"}
|
|
@@ -283,7 +196,6 @@ func (s *DockerSuite) TestLogsSince(c *check.C) {
|
|
|
c.Fatalf("unexpected log message returned=%v, since=%v\nout=%v", v, since, out)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// Test with default value specified and parameter omitted
|
|
|
expected := []string{"log1", "log2", "log3"}
|
|
|
for _, cmd := range []*exec.Cmd{
|
|
@@ -303,20 +215,12 @@ func (s *DockerSuite) TestLogsSince(c *check.C) {
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestLogsSinceFutureFollow(c *check.C) {
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "/bin/sh", "-c", `for i in $(seq 1 5); do date +%s; sleep 1; done`)
|
|
|
- out, _, err := runCommandWithOutput(runCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("run failed with errors: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", `for i in $(seq 1 5); do date +%s; sleep 1; done`)
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|
|
|
now := daemonTime(c).Unix()
|
|
|
since := now + 2
|
|
|
- logCmd := exec.Command(dockerBinary, "logs", "-f", fmt.Sprintf("--since=%v", since), cleanedContainerID)
|
|
|
- out, _, err = runCommandWithOutput(logCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to log container: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ = dockerCmd(c, "logs", "-f", fmt.Sprintf("--since=%v", since), cleanedContainerID)
|
|
|
lines := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
if len(lines) == 0 {
|
|
|
c.Fatal("got no log lines")
|
|
@@ -334,12 +238,7 @@ func (s *DockerSuite) TestLogsSinceFutureFollow(c *check.C) {
|
|
|
|
|
|
// Regression test for #8832
|
|
|
func (s *DockerSuite) TestLogsFollowSlowStdoutConsumer(c *check.C) {
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "/bin/sh", "-c", `usleep 200000;yes X | head -c 200000`)
|
|
|
-
|
|
|
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("run failed with errors: %s, %v", out, err)
|
|
|
- }
|
|
|
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", `usleep 200000;yes X | head -c 200000`)
|
|
|
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
|
|
|