From 42d47c31367d288c7a9ae3acff635e995254469c Mon Sep 17 00:00:00 2001 From: Todd Whiteman Date: Wed, 8 Apr 2015 16:32:45 -0700 Subject: [PATCH] fix #12188 integration-cli: tests using "sleep" can timeout too early - change to "top" instead Signed-off-by: Todd Whiteman --- integration-cli/docker_cli_exec_test.go | 8 +++--- integration-cli/docker_cli_kill_test.go | 8 +++--- integration-cli/docker_cli_links_test.go | 18 ++++++------- integration-cli/docker_cli_pause_test.go | 16 ++--------- integration-cli/docker_cli_ps_test.go | 4 +-- integration-cli/docker_cli_top_test.go | 34 ++++++++++++------------ 6 files changed, 38 insertions(+), 50 deletions(-) diff --git a/integration-cli/docker_cli_exec_test.go b/integration-cli/docker_cli_exec_test.go index f06e20a84..9fcee32a7 100644 --- a/integration-cli/docker_cli_exec_test.go +++ b/integration-cli/docker_cli_exec_test.go @@ -19,7 +19,7 @@ import ( func TestExec(t *testing.T) { defer deleteAllContainers() - runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && sleep 100") + runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top") if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil { t.Fatal(out, err) } @@ -82,7 +82,7 @@ func TestExecInteractiveStdinClose(t *testing.T) { func TestExecInteractive(t *testing.T) { defer deleteAllContainers() - runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && sleep 100") + runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top") if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil { t.Fatal(out, err) } @@ -500,12 +500,12 @@ func TestLinksPingLinkedContainersOnRename(t *testing.T) { defer deleteAllContainers() var out string - out, _, _ = dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10") + out, _, _ = dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "top") idA := strings.TrimSpace(out) if idA == "" { t.Fatal(out, "id should not be nil") } - out, _, _ = dockerCmd(t, "run", "-d", "--link", "container1:alias1", "--name", "container2", "busybox", "sleep", "10") + out, _, _ = dockerCmd(t, "run", "-d", "--link", "container1:alias1", "--name", "container2", "busybox", "top") idB := strings.TrimSpace(out) if idB == "" { t.Fatal(out, "id should not be nil") diff --git a/integration-cli/docker_cli_kill_test.go b/integration-cli/docker_cli_kill_test.go index 7a0d000a0..cd86c0c56 100644 --- a/integration-cli/docker_cli_kill_test.go +++ b/integration-cli/docker_cli_kill_test.go @@ -7,7 +7,7 @@ import ( ) func TestKillContainer(t *testing.T) { - runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 10") + runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") out, _, err := runCommandWithOutput(runCmd) if err != nil { t.Fatal(out, err) @@ -37,11 +37,11 @@ func TestKillContainer(t *testing.T) { deleteContainer(cleanedContainerID) - logDone("kill - kill container running sleep 10") + logDone("kill - kill container running top") } func TestKillDifferentUserContainer(t *testing.T) { - runCmd := exec.Command(dockerBinary, "run", "-u", "daemon", "-d", "busybox", "sh", "-c", "sleep 10") + runCmd := exec.Command(dockerBinary, "run", "-u", "daemon", "-d", "busybox", "top") out, _, err := runCommandWithOutput(runCmd) if err != nil { t.Fatal(out, err) @@ -71,5 +71,5 @@ func TestKillDifferentUserContainer(t *testing.T) { deleteContainer(cleanedContainerID) - logDone("kill - kill container running sleep 10 from a different user") + logDone("kill - kill container running top from a different user") } diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index 80bdfc955..04718c23f 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -110,9 +110,9 @@ func TestLinksPingLinkedContainers(t *testing.T) { func TestLinksPingLinkedContainersAfterRename(t *testing.T) { defer deleteAllContainers() - out, _, _ := dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10") + out, _, _ := dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "top") idA := strings.TrimSpace(out) - out, _, _ = dockerCmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10") + out, _, _ = dockerCmd(t, "run", "-d", "--name", "container2", "busybox", "top") idB := strings.TrimSpace(out) dockerCmd(t, "rename", "container1", "container_new") dockerCmd(t, "run", "--rm", "--link", "container_new:alias1", "--link", "container2:alias2", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1") @@ -126,8 +126,8 @@ func TestLinksIpTablesRulesWhenLinkAndUnlink(t *testing.T) { testRequires(t, SameHostDaemon) defer deleteAllContainers() - dockerCmd(t, "run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "sleep", "10") - dockerCmd(t, "run", "-d", "--name", "parent", "--link", "child:http", "busybox", "sleep", "10") + dockerCmd(t, "run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "top") + dockerCmd(t, "run", "-d", "--name", "parent", "--link", "child:http", "busybox", "top") childIP := findContainerIP(t, "child") parentIP := findContainerIP(t, "parent") @@ -155,9 +155,9 @@ func TestLinksInspectLinksStarted(t *testing.T) { result []string ) defer deleteAllContainers() - dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10") - dockerCmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10") - dockerCmd(t, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "sleep", "10") + dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "top") + dockerCmd(t, "run", "-d", "--name", "container2", "busybox", "top") + dockerCmd(t, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "top") links, err := inspectFieldJSON("testinspectlink", "HostConfig.Links") if err != nil { t.Fatal(err) @@ -184,8 +184,8 @@ func TestLinksInspectLinksStopped(t *testing.T) { result []string ) defer deleteAllContainers() - dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10") - dockerCmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10") + dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "top") + dockerCmd(t, "run", "-d", "--name", "container2", "busybox", "top") dockerCmd(t, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true") links, err := inspectFieldJSON("testinspectlink", "HostConfig.Links") if err != nil { diff --git a/integration-cli/docker_cli_pause_test.go b/integration-cli/docker_cli_pause_test.go index 2ba8cb0ae..41147b206 100644 --- a/integration-cli/docker_cli_pause_test.go +++ b/integration-cli/docker_cli_pause_test.go @@ -14,7 +14,7 @@ func TestPause(t *testing.T) { name := "testeventpause" out, _, _ := dockerCmd(t, "images", "-q") image := strings.Split(out, "\n")[0] - dockerCmd(t, "run", "-d", "--name", name, image, "sleep", "2") + dockerCmd(t, "run", "-d", "--name", name, image, "top") dockerCmd(t, "pause", name) pausedContainers, err := getSliceOfPausedContainers() @@ -44,11 +44,6 @@ func TestPause(t *testing.T) { t.Fatalf("event should be unpause, not %#v", unpauseEvent) } - waitCmd := exec.Command(dockerBinary, "wait", name) - if waitOut, _, err := runCommandWithOutput(waitCmd); err != nil { - t.Fatalf("error thrown while waiting for container: %s, %v", waitOut, err) - } - logDone("pause - pause/unpause is logged") } @@ -63,7 +58,7 @@ func TestPauseMultipleContainers(t *testing.T) { out, _, _ := dockerCmd(t, "images", "-q") image := strings.Split(out, "\n")[0] for _, name := range containers { - dockerCmd(t, "run", "-d", "--name", name, image, "sleep", "2") + dockerCmd(t, "run", "-d", "--name", name, image, "top") } dockerCmd(t, append([]string{"pause"}, containers...)...) pausedContainers, err := getSliceOfPausedContainers() @@ -101,12 +96,5 @@ func TestPauseMultipleContainers(t *testing.T) { } } - for _, name := range containers { - waitCmd := exec.Command(dockerBinary, "wait", name) - if waitOut, _, err := runCommandWithOutput(waitCmd); err != nil { - t.Fatalf("error thrown while waiting for container: %s, %v", waitOut, err) - } - } - logDone("pause - multi pause/unpause is logged") } diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index 9ac347410..deb426fce 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/integration-cli/docker_cli_ps_test.go @@ -377,7 +377,7 @@ func TestPsListContainersFilterID(t *testing.T) { firstID := strings.TrimSpace(out) // start another container - runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 360") + runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top") if out, _, err = runCommandWithOutput(runCmd); err != nil { t.Fatal(out, err) } @@ -407,7 +407,7 @@ func TestPsListContainersFilterName(t *testing.T) { firstID := strings.TrimSpace(out) // start another container - runCmd = exec.Command(dockerBinary, "run", "-d", "--name=b_name_to_match", "busybox", "sh", "-c", "sleep 360") + runCmd = exec.Command(dockerBinary, "run", "-d", "--name=b_name_to_match", "busybox", "top") if out, _, err = runCommandWithOutput(runCmd); err != nil { t.Fatal(out, err) } diff --git a/integration-cli/docker_cli_top_test.go b/integration-cli/docker_cli_top_test.go index cd996af76..b5dca0be9 100644 --- a/integration-cli/docker_cli_top_test.go +++ b/integration-cli/docker_cli_top_test.go @@ -7,7 +7,7 @@ import ( ) func TestTopMultipleArgs(t *testing.T) { - runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "sleep", "20") + runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "top") out, _, err := runCommandWithOutput(runCmd) if err != nil { t.Fatalf("failed to start the container: %s, %v", out, err) @@ -30,7 +30,7 @@ func TestTopMultipleArgs(t *testing.T) { } func TestTopNonPrivileged(t *testing.T) { - runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "sleep", "20") + runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "top") out, _, err := runCommandWithOutput(runCmd) if err != nil { t.Fatalf("failed to start the container: %s, %v", out, err) @@ -57,19 +57,19 @@ func TestTopNonPrivileged(t *testing.T) { deleteContainer(cleanedContainerID) - if !strings.Contains(out1, "sleep 20") && !strings.Contains(out2, "sleep 20") { - t.Fatal("top should've listed `sleep 20` in the process list, but failed twice") - } else if !strings.Contains(out1, "sleep 20") { - t.Fatal("top should've listed `sleep 20` in the process list, but failed the first time") - } else if !strings.Contains(out2, "sleep 20") { - t.Fatal("top should've listed `sleep 20` in the process list, but failed the second itime") + if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") { + t.Fatal("top should've listed `top` in the process list, but failed twice") + } else if !strings.Contains(out1, "top") { + t.Fatal("top should've listed `top` in the process list, but failed the first time") + } else if !strings.Contains(out2, "top") { + t.Fatal("top should've listed `top` in the process list, but failed the second itime") } - logDone("top - sleep process should be listed in non privileged mode") + logDone("top - top process should be listed in non privileged mode") } func TestTopPrivileged(t *testing.T) { - runCmd := exec.Command(dockerBinary, "run", "--privileged", "-i", "-d", "busybox", "sleep", "20") + runCmd := exec.Command(dockerBinary, "run", "--privileged", "-i", "-d", "busybox", "top") out, _, err := runCommandWithOutput(runCmd) if err != nil { t.Fatalf("failed to start the container: %s, %v", out, err) @@ -96,13 +96,13 @@ func TestTopPrivileged(t *testing.T) { deleteContainer(cleanedContainerID) - if !strings.Contains(out1, "sleep 20") && !strings.Contains(out2, "sleep 20") { - t.Fatal("top should've listed `sleep 20` in the process list, but failed twice") - } else if !strings.Contains(out1, "sleep 20") { - t.Fatal("top should've listed `sleep 20` in the process list, but failed the first time") - } else if !strings.Contains(out2, "sleep 20") { - t.Fatal("top should've listed `sleep 20` in the process list, but failed the second itime") + if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") { + t.Fatal("top should've listed `top` in the process list, but failed twice") + } else if !strings.Contains(out1, "top") { + t.Fatal("top should've listed `top` in the process list, but failed the first time") + } else if !strings.Contains(out2, "top") { + t.Fatal("top should've listed `top` in the process list, but failed the second itime") } - logDone("top - sleep process should be listed in privileged mode") + logDone("top - top process should be listed in privileged mode") }