Browse code

Merge pull request #8691 from crosbymichael/fix-integration-race

Fix racy integration tests

Tibor Vass authored on 2014/10/22 10:06:01
Showing 1 changed files
... ...
@@ -16,20 +16,21 @@ func TestContainerApiGetAll(t *testing.T) {
16 16
 		t.Fatalf("Cannot query container count: %v", err)
17 17
 	}
18 18
 
19
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
19
+	name := "getall"
20
+	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
20 21
 	out, _, err := runCommandWithOutput(runCmd)
21 22
 	if err != nil {
22 23
 		t.Fatalf("Error on container creation: %v, output: %q", err, out)
23 24
 	}
24 25
 
25
-	testContainerId := stripTrailingCharacters(out)
26
-
27 26
 	body, err := sockRequest("GET", "/containers/json?all=1")
28 27
 	if err != nil {
29 28
 		t.Fatalf("GET all containers sockRequest failed: %v", err)
30 29
 	}
31 30
 
32
-	var inspectJSON []map[string]interface{}
31
+	var inspectJSON []struct {
32
+		Names []string
33
+	}
33 34
 	if err = json.Unmarshal(body, &inspectJSON); err != nil {
34 35
 		t.Fatalf("unable to unmarshal response body: %v", err)
35 36
 	}
... ...
@@ -37,8 +38,9 @@ func TestContainerApiGetAll(t *testing.T) {
37 37
 	if len(inspectJSON) != startCount+1 {
38 38
 		t.Fatalf("Expected %d container(s), %d found (started with: %d)", startCount+1, len(inspectJSON), startCount)
39 39
 	}
40
-	if id, _ := inspectJSON[0]["Id"]; id != testContainerId {
41
-		t.Fatalf("Container ID mismatch. Expected: %s, received: %s\n", testContainerId, id)
40
+
41
+	if actual := inspectJSON[0].Names[0]; actual != "/"+name {
42
+		t.Fatalf("Container Name mismatch. Expected: %q, received: %q\n", "/"+name, actual)
42 43
 	}
43 44
 
44 45
 	deleteAllContainers()
... ...
@@ -47,15 +49,14 @@ func TestContainerApiGetAll(t *testing.T) {
47 47
 }
48 48
 
49 49
 func TestContainerApiGetExport(t *testing.T) {
50
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "touch", "/test")
50
+	name := "exportcontainer"
51
+	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test")
51 52
 	out, _, err := runCommandWithOutput(runCmd)
52 53
 	if err != nil {
53 54
 		t.Fatalf("Error on container creation: %v, output: %q", err, out)
54 55
 	}
55 56
 
56
-	testContainerId := stripTrailingCharacters(out)
57
-
58
-	body, err := sockRequest("GET", "/containers/"+testContainerId+"/export")
57
+	body, err := sockRequest("GET", "/containers/"+name+"/export")
59 58
 	if err != nil {
60 59
 		t.Fatalf("GET containers/export sockRequest failed: %v", err)
61 60
 	}
... ...
@@ -84,15 +85,14 @@ func TestContainerApiGetExport(t *testing.T) {
84 84
 }
85 85
 
86 86
 func TestContainerApiGetChanges(t *testing.T) {
87
-	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "rm", "/etc/passwd")
87
+	name := "changescontainer"
88
+	runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "rm", "/etc/passwd")
88 89
 	out, _, err := runCommandWithOutput(runCmd)
89 90
 	if err != nil {
90 91
 		t.Fatalf("Error on container creation: %v, output: %q", err, out)
91 92
 	}
92 93
 
93
-	testContainerId := stripTrailingCharacters(out)
94
-
95
-	body, err := sockRequest("GET", "/containers/"+testContainerId+"/changes")
94
+	body, err := sockRequest("GET", "/containers/"+name+"/changes")
96 95
 	if err != nil {
97 96
 		t.Fatalf("GET containers/changes sockRequest failed: %v", err)
98 97
 	}