Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net> (github: creack)
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,76 @@ |
| 0 |
+package main |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ "os/exec" |
|
| 5 |
+ "testing" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+// This used to work, it test a log of PageSize-1 (gh#4851) |
|
| 9 |
+func TestLogsContainerSmallerThanPage(t *testing.T) {
|
|
| 10 |
+ testLen := 32767 |
|
| 11 |
+ runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen))
|
|
| 12 |
+ out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
| 13 |
+ errorOut(err, t, fmt.Sprintf("run failed with errors: %v", err))
|
|
| 14 |
+ |
|
| 15 |
+ cleanedContainerID := stripTrailingCharacters(out) |
|
| 16 |
+ exec.Command(dockerBinary, "wait", cleanedContainerID).Run() |
|
| 17 |
+ |
|
| 18 |
+ logsCmd := exec.Command(dockerBinary, "logs", cleanedContainerID) |
|
| 19 |
+ out, _, _, err = runCommandWithStdoutStderr(logsCmd) |
|
| 20 |
+ errorOut(err, t, fmt.Sprintf("failed to log container: %v %v", out, err))
|
|
| 21 |
+ |
|
| 22 |
+ if len(out) != testLen+1 {
|
|
| 23 |
+ t.Fatalf("Expected log length of %d, received %d\n", testLen+1, len(out))
|
|
| 24 |
+ } |
|
| 25 |
+ |
|
| 26 |
+ go deleteContainer(cleanedContainerID) |
|
| 27 |
+ |
|
| 28 |
+ logDone("logs - logs container running echo smaller than page size")
|
|
| 29 |
+} |
|
| 30 |
+ |
|
| 31 |
+// Regression test: When going over the PageSize, it used to panic (gh#4851) |
|
| 32 |
+func TestLogsContainerBiggerThanPage(t *testing.T) {
|
|
| 33 |
+ testLen := 32768 |
|
| 34 |
+ runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen))
|
|
| 35 |
+ out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
| 36 |
+ errorOut(err, t, fmt.Sprintf("run failed with errors: %v", err))
|
|
| 37 |
+ |
|
| 38 |
+ cleanedContainerID := stripTrailingCharacters(out) |
|
| 39 |
+ exec.Command(dockerBinary, "wait", cleanedContainerID).Run() |
|
| 40 |
+ |
|
| 41 |
+ logsCmd := exec.Command(dockerBinary, "logs", cleanedContainerID) |
|
| 42 |
+ out, _, _, err = runCommandWithStdoutStderr(logsCmd) |
|
| 43 |
+ errorOut(err, t, fmt.Sprintf("failed to log container: %v %v", out, err))
|
|
| 44 |
+ |
|
| 45 |
+ if len(out) != testLen+1 {
|
|
| 46 |
+ t.Fatalf("Expected log length of %d, received %d\n", testLen+1, len(out))
|
|
| 47 |
+ } |
|
| 48 |
+ |
|
| 49 |
+ go deleteContainer(cleanedContainerID) |
|
| 50 |
+ |
|
| 51 |
+ logDone("logs - logs container running echo bigger than page size")
|
|
| 52 |
+} |
|
| 53 |
+ |
|
| 54 |
+// Regression test: When going much over the PageSize, it used to block (gh#4851) |
|
| 55 |
+func TestLogsContainerMuchBiggerThanPage(t *testing.T) {
|
|
| 56 |
+ testLen := 33000 |
|
| 57 |
+ runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n =; done; echo", testLen))
|
|
| 58 |
+ out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
| 59 |
+ errorOut(err, t, fmt.Sprintf("run failed with errors: %v", err))
|
|
| 60 |
+ |
|
| 61 |
+ cleanedContainerID := stripTrailingCharacters(out) |
|
| 62 |
+ exec.Command(dockerBinary, "wait", cleanedContainerID).Run() |
|
| 63 |
+ |
|
| 64 |
+ logsCmd := exec.Command(dockerBinary, "logs", cleanedContainerID) |
|
| 65 |
+ out, _, _, err = runCommandWithStdoutStderr(logsCmd) |
|
| 66 |
+ errorOut(err, t, fmt.Sprintf("failed to log container: %v %v", out, err))
|
|
| 67 |
+ |
|
| 68 |
+ if len(out) != testLen+1 {
|
|
| 69 |
+ t.Fatalf("Expected log length of %d, received %d\n", testLen+1, len(out))
|
|
| 70 |
+ } |
|
| 71 |
+ |
|
| 72 |
+ go deleteContainer(cleanedContainerID) |
|
| 73 |
+ |
|
| 74 |
+ logDone("logs - logs container running echo much bigger than page size")
|
|
| 75 |
+} |