Browse code

fix #12188 integration-cli: tests using "sleep" can timeout too early - change to "top" instead

Signed-off-by: Todd Whiteman <todd.whiteman@joyent.com>

Todd Whiteman authored on 2015/04/09 08:32:45
Showing 6 changed files
... ...
@@ -19,7 +19,7 @@ import (
19 19
 func TestExec(t *testing.T) {
20 20
 	defer deleteAllContainers()
21 21
 
22
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && sleep 100")
22
+	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
23 23
 	if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
24 24
 		t.Fatal(out, err)
25 25
 	}
... ...
@@ -82,7 +82,7 @@ func TestExecInteractiveStdinClose(t *testing.T) {
82 82
 func TestExecInteractive(t *testing.T) {
83 83
 	defer deleteAllContainers()
84 84
 
85
-	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && sleep 100")
85
+	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "testing", "busybox", "sh", "-c", "echo test > /tmp/file && top")
86 86
 	if out, _, _, err := runCommandWithStdoutStderr(runCmd); err != nil {
87 87
 		t.Fatal(out, err)
88 88
 	}
... ...
@@ -500,12 +500,12 @@ func TestLinksPingLinkedContainersOnRename(t *testing.T) {
500 500
 	defer deleteAllContainers()
501 501
 
502 502
 	var out string
503
-	out, _, _ = dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10")
503
+	out, _, _ = dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "top")
504 504
 	idA := strings.TrimSpace(out)
505 505
 	if idA == "" {
506 506
 		t.Fatal(out, "id should not be nil")
507 507
 	}
508
-	out, _, _ = dockerCmd(t, "run", "-d", "--link", "container1:alias1", "--name", "container2", "busybox", "sleep", "10")
508
+	out, _, _ = dockerCmd(t, "run", "-d", "--link", "container1:alias1", "--name", "container2", "busybox", "top")
509 509
 	idB := strings.TrimSpace(out)
510 510
 	if idB == "" {
511 511
 		t.Fatal(out, "id should not be nil")
... ...
@@ -7,7 +7,7 @@ import (
7 7
 )
8 8
 
9 9
 func TestKillContainer(t *testing.T) {
10
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 10")
10
+	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
11 11
 	out, _, err := runCommandWithOutput(runCmd)
12 12
 	if err != nil {
13 13
 		t.Fatal(out, err)
... ...
@@ -37,11 +37,11 @@ func TestKillContainer(t *testing.T) {
37 37
 
38 38
 	deleteContainer(cleanedContainerID)
39 39
 
40
-	logDone("kill - kill container running sleep 10")
40
+	logDone("kill - kill container running top")
41 41
 }
42 42
 
43 43
 func TestKillDifferentUserContainer(t *testing.T) {
44
-	runCmd := exec.Command(dockerBinary, "run", "-u", "daemon", "-d", "busybox", "sh", "-c", "sleep 10")
44
+	runCmd := exec.Command(dockerBinary, "run", "-u", "daemon", "-d", "busybox", "top")
45 45
 	out, _, err := runCommandWithOutput(runCmd)
46 46
 	if err != nil {
47 47
 		t.Fatal(out, err)
... ...
@@ -71,5 +71,5 @@ func TestKillDifferentUserContainer(t *testing.T) {
71 71
 
72 72
 	deleteContainer(cleanedContainerID)
73 73
 
74
-	logDone("kill - kill container running sleep 10 from a different user")
74
+	logDone("kill - kill container running top from a different user")
75 75
 }
... ...
@@ -110,9 +110,9 @@ func TestLinksPingLinkedContainers(t *testing.T) {
110 110
 func TestLinksPingLinkedContainersAfterRename(t *testing.T) {
111 111
 	defer deleteAllContainers()
112 112
 
113
-	out, _, _ := dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10")
113
+	out, _, _ := dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "top")
114 114
 	idA := strings.TrimSpace(out)
115
-	out, _, _ = dockerCmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10")
115
+	out, _, _ = dockerCmd(t, "run", "-d", "--name", "container2", "busybox", "top")
116 116
 	idB := strings.TrimSpace(out)
117 117
 	dockerCmd(t, "rename", "container1", "container_new")
118 118
 	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) {
126 126
 	testRequires(t, SameHostDaemon)
127 127
 	defer deleteAllContainers()
128 128
 
129
-	dockerCmd(t, "run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "sleep", "10")
130
-	dockerCmd(t, "run", "-d", "--name", "parent", "--link", "child:http", "busybox", "sleep", "10")
129
+	dockerCmd(t, "run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "top")
130
+	dockerCmd(t, "run", "-d", "--name", "parent", "--link", "child:http", "busybox", "top")
131 131
 
132 132
 	childIP := findContainerIP(t, "child")
133 133
 	parentIP := findContainerIP(t, "parent")
... ...
@@ -155,9 +155,9 @@ func TestLinksInspectLinksStarted(t *testing.T) {
155 155
 		result   []string
156 156
 	)
157 157
 	defer deleteAllContainers()
158
-	dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10")
159
-	dockerCmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10")
160
-	dockerCmd(t, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "sleep", "10")
158
+	dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "top")
159
+	dockerCmd(t, "run", "-d", "--name", "container2", "busybox", "top")
160
+	dockerCmd(t, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "top")
161 161
 	links, err := inspectFieldJSON("testinspectlink", "HostConfig.Links")
162 162
 	if err != nil {
163 163
 		t.Fatal(err)
... ...
@@ -184,8 +184,8 @@ func TestLinksInspectLinksStopped(t *testing.T) {
184 184
 		result   []string
185 185
 	)
186 186
 	defer deleteAllContainers()
187
-	dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10")
188
-	dockerCmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10")
187
+	dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "top")
188
+	dockerCmd(t, "run", "-d", "--name", "container2", "busybox", "top")
189 189
 	dockerCmd(t, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true")
190 190
 	links, err := inspectFieldJSON("testinspectlink", "HostConfig.Links")
191 191
 	if err != nil {
... ...
@@ -14,7 +14,7 @@ func TestPause(t *testing.T) {
14 14
 	name := "testeventpause"
15 15
 	out, _, _ := dockerCmd(t, "images", "-q")
16 16
 	image := strings.Split(out, "\n")[0]
17
-	dockerCmd(t, "run", "-d", "--name", name, image, "sleep", "2")
17
+	dockerCmd(t, "run", "-d", "--name", name, image, "top")
18 18
 
19 19
 	dockerCmd(t, "pause", name)
20 20
 	pausedContainers, err := getSliceOfPausedContainers()
... ...
@@ -44,11 +44,6 @@ func TestPause(t *testing.T) {
44 44
 		t.Fatalf("event should be unpause, not %#v", unpauseEvent)
45 45
 	}
46 46
 
47
-	waitCmd := exec.Command(dockerBinary, "wait", name)
48
-	if waitOut, _, err := runCommandWithOutput(waitCmd); err != nil {
49
-		t.Fatalf("error thrown while waiting for container: %s, %v", waitOut, err)
50
-	}
51
-
52 47
 	logDone("pause - pause/unpause is logged")
53 48
 }
54 49
 
... ...
@@ -63,7 +58,7 @@ func TestPauseMultipleContainers(t *testing.T) {
63 63
 	out, _, _ := dockerCmd(t, "images", "-q")
64 64
 	image := strings.Split(out, "\n")[0]
65 65
 	for _, name := range containers {
66
-		dockerCmd(t, "run", "-d", "--name", name, image, "sleep", "2")
66
+		dockerCmd(t, "run", "-d", "--name", name, image, "top")
67 67
 	}
68 68
 	dockerCmd(t, append([]string{"pause"}, containers...)...)
69 69
 	pausedContainers, err := getSliceOfPausedContainers()
... ...
@@ -101,12 +96,5 @@ func TestPauseMultipleContainers(t *testing.T) {
101 101
 		}
102 102
 	}
103 103
 
104
-	for _, name := range containers {
105
-		waitCmd := exec.Command(dockerBinary, "wait", name)
106
-		if waitOut, _, err := runCommandWithOutput(waitCmd); err != nil {
107
-			t.Fatalf("error thrown while waiting for container: %s, %v", waitOut, err)
108
-		}
109
-	}
110
-
111 104
 	logDone("pause - multi pause/unpause is logged")
112 105
 }
... ...
@@ -377,7 +377,7 @@ func TestPsListContainersFilterID(t *testing.T) {
377 377
 	firstID := strings.TrimSpace(out)
378 378
 
379 379
 	// start another container
380
-	runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 360")
380
+	runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
381 381
 	if out, _, err = runCommandWithOutput(runCmd); err != nil {
382 382
 		t.Fatal(out, err)
383 383
 	}
... ...
@@ -407,7 +407,7 @@ func TestPsListContainersFilterName(t *testing.T) {
407 407
 	firstID := strings.TrimSpace(out)
408 408
 
409 409
 	// start another container
410
-	runCmd = exec.Command(dockerBinary, "run", "-d", "--name=b_name_to_match", "busybox", "sh", "-c", "sleep 360")
410
+	runCmd = exec.Command(dockerBinary, "run", "-d", "--name=b_name_to_match", "busybox", "top")
411 411
 	if out, _, err = runCommandWithOutput(runCmd); err != nil {
412 412
 		t.Fatal(out, err)
413 413
 	}
... ...
@@ -7,7 +7,7 @@ import (
7 7
 )
8 8
 
9 9
 func TestTopMultipleArgs(t *testing.T) {
10
-	runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "sleep", "20")
10
+	runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "top")
11 11
 	out, _, err := runCommandWithOutput(runCmd)
12 12
 	if err != nil {
13 13
 		t.Fatalf("failed to start the container: %s, %v", out, err)
... ...
@@ -30,7 +30,7 @@ func TestTopMultipleArgs(t *testing.T) {
30 30
 }
31 31
 
32 32
 func TestTopNonPrivileged(t *testing.T) {
33
-	runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "sleep", "20")
33
+	runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "top")
34 34
 	out, _, err := runCommandWithOutput(runCmd)
35 35
 	if err != nil {
36 36
 		t.Fatalf("failed to start the container: %s, %v", out, err)
... ...
@@ -57,19 +57,19 @@ func TestTopNonPrivileged(t *testing.T) {
57 57
 
58 58
 	deleteContainer(cleanedContainerID)
59 59
 
60
-	if !strings.Contains(out1, "sleep 20") && !strings.Contains(out2, "sleep 20") {
61
-		t.Fatal("top should've listed `sleep 20` in the process list, but failed twice")
62
-	} else if !strings.Contains(out1, "sleep 20") {
63
-		t.Fatal("top should've listed `sleep 20` in the process list, but failed the first time")
64
-	} else if !strings.Contains(out2, "sleep 20") {
65
-		t.Fatal("top should've listed `sleep 20` in the process list, but failed the second itime")
60
+	if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
61
+		t.Fatal("top should've listed `top` in the process list, but failed twice")
62
+	} else if !strings.Contains(out1, "top") {
63
+		t.Fatal("top should've listed `top` in the process list, but failed the first time")
64
+	} else if !strings.Contains(out2, "top") {
65
+		t.Fatal("top should've listed `top` in the process list, but failed the second itime")
66 66
 	}
67 67
 
68
-	logDone("top - sleep process should be listed in non privileged mode")
68
+	logDone("top - top process should be listed in non privileged mode")
69 69
 }
70 70
 
71 71
 func TestTopPrivileged(t *testing.T) {
72
-	runCmd := exec.Command(dockerBinary, "run", "--privileged", "-i", "-d", "busybox", "sleep", "20")
72
+	runCmd := exec.Command(dockerBinary, "run", "--privileged", "-i", "-d", "busybox", "top")
73 73
 	out, _, err := runCommandWithOutput(runCmd)
74 74
 	if err != nil {
75 75
 		t.Fatalf("failed to start the container: %s, %v", out, err)
... ...
@@ -96,13 +96,13 @@ func TestTopPrivileged(t *testing.T) {
96 96
 
97 97
 	deleteContainer(cleanedContainerID)
98 98
 
99
-	if !strings.Contains(out1, "sleep 20") && !strings.Contains(out2, "sleep 20") {
100
-		t.Fatal("top should've listed `sleep 20` in the process list, but failed twice")
101
-	} else if !strings.Contains(out1, "sleep 20") {
102
-		t.Fatal("top should've listed `sleep 20` in the process list, but failed the first time")
103
-	} else if !strings.Contains(out2, "sleep 20") {
104
-		t.Fatal("top should've listed `sleep 20` in the process list, but failed the second itime")
99
+	if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
100
+		t.Fatal("top should've listed `top` in the process list, but failed twice")
101
+	} else if !strings.Contains(out1, "top") {
102
+		t.Fatal("top should've listed `top` in the process list, but failed the first time")
103
+	} else if !strings.Contains(out2, "top") {
104
+		t.Fatal("top should've listed `top` in the process list, but failed the second itime")
105 105
 	}
106 106
 
107
-	logDone("top - sleep process should be listed in privileged mode")
107
+	logDone("top - top process should be listed in privileged mode")
108 108
 }