Browse code

Merge pull request #2385 from dotcloud/suppress_even_more_warnings_test

Improve tests again, remove warnings and prevent some mount issues

Michael Crosby authored on 2013/10/26 07:04:56
Showing 6 changed files
... ...
@@ -731,7 +731,7 @@ func TestPostContainersRestart(t *testing.T) {
731 731
 	container, err := runtime.Create(
732 732
 		&Config{
733 733
 			Image:     GetTestImage(runtime).ID,
734
-			Cmd:       []string{"/bin/cat"},
734
+			Cmd:       []string{"/bin/top"},
735 735
 			OpenStdin: true,
736 736
 		},
737 737
 	)
... ...
@@ -837,7 +837,7 @@ func TestPostContainersStop(t *testing.T) {
837 837
 	container, err := runtime.Create(
838 838
 		&Config{
839 839
 			Image:     GetTestImage(runtime).ID,
840
-			Cmd:       []string{"/bin/cat"},
840
+			Cmd:       []string{"/bin/top"},
841 841
 			OpenStdin: true,
842 842
 		},
843 843
 	)
... ...
@@ -84,10 +84,24 @@ func TestRunHostname(t *testing.T) {
84 84
 		}
85 85
 	})
86 86
 
87
+	container := globalRuntime.List()[0]
88
+
87 89
 	setTimeout(t, "CmdRun timed out", 10*time.Second, func() {
88 90
 		<-c
91
+
92
+		go func() {
93
+			cli.CmdWait(container.ID)
94
+		}()
95
+
96
+		if _, err := bufio.NewReader(stdout).ReadString('\n'); err != nil {
97
+			t.Fatal(err)
98
+		}
89 99
 	})
90 100
 
101
+	// Cleanup pipes
102
+	if err := closeWrap(stdout, stdoutPipe); err != nil {
103
+		t.Fatal(err)
104
+	}
91 105
 }
92 106
 
93 107
 // TestRunWorkdir checks that 'docker run -w' correctly sets a custom working directory
... ...
@@ -115,10 +129,24 @@ func TestRunWorkdir(t *testing.T) {
115 115
 		}
116 116
 	})
117 117
 
118
+	container := globalRuntime.List()[0]
119
+
118 120
 	setTimeout(t, "CmdRun timed out", 10*time.Second, func() {
119 121
 		<-c
122
+
123
+		go func() {
124
+			cli.CmdWait(container.ID)
125
+		}()
126
+
127
+		if _, err := bufio.NewReader(stdout).ReadString('\n'); err != nil {
128
+			t.Fatal(err)
129
+		}
120 130
 	})
121 131
 
132
+	// Cleanup pipes
133
+	if err := closeWrap(stdout, stdoutPipe); err != nil {
134
+		t.Fatal(err)
135
+	}
122 136
 }
123 137
 
124 138
 // TestRunWorkdirExists checks that 'docker run -w' correctly sets a custom working directory, even if it exists
... ...
@@ -146,10 +174,24 @@ func TestRunWorkdirExists(t *testing.T) {
146 146
 		}
147 147
 	})
148 148
 
149
+	container := globalRuntime.List()[0]
150
+
149 151
 	setTimeout(t, "CmdRun timed out", 5*time.Second, func() {
150 152
 		<-c
153
+
154
+		go func() {
155
+			cli.CmdWait(container.ID)
156
+		}()
157
+
158
+		if _, err := bufio.NewReader(stdout).ReadString('\n'); err != nil {
159
+			t.Fatal(err)
160
+		}
151 161
 	})
152 162
 
163
+	// Cleanup pipes
164
+	if err := closeWrap(stdout, stdoutPipe); err != nil {
165
+		t.Fatal(err)
166
+	}
153 167
 }
154 168
 
155 169
 func TestRunExit(t *testing.T) {
... ...
@@ -1249,6 +1249,12 @@ func (container *Container) Mounted() (bool, error) {
1249 1249
 }
1250 1250
 
1251 1251
 func (container *Container) Unmount() error {
1252
+	if _, err := os.Stat(container.RootfsPath()); err != nil {
1253
+		if os.IsNotExist(err) {
1254
+			return nil
1255
+		}
1256
+		return err
1257
+	}
1252 1258
 	return Unmount(container.RootfsPath())
1253 1259
 }
1254 1260
 
... ...
@@ -1593,7 +1593,6 @@ func TestMultipleVolumesFrom(t *testing.T) {
1593 1593
 		t.Fatal(err)
1594 1594
 	}
1595 1595
 
1596
-	t.Log(container3.Volumes)
1597 1596
 	if container3.Volumes["/test"] != container.Volumes["/test"] {
1598 1597
 		t.Fail()
1599 1598
 	}
... ...
@@ -44,7 +44,6 @@ func NewEchoServer(t *testing.T, proto, address string) EchoServer {
44 44
 		}
45 45
 		server = &UDPEchoServer{conn: socket, testCtx: t}
46 46
 	}
47
-	t.Logf("EchoServer listening on %v/%v\n", proto, server.LocalAddr().String())
48 47
 	return server
49 48
 }
50 49
 
... ...
@@ -56,10 +55,7 @@ func (server *TCPEchoServer) Run() {
56 56
 				return
57 57
 			}
58 58
 			go func(client net.Conn) {
59
-				server.testCtx.Logf("TCP client accepted on the EchoServer\n")
60
-				written, err := io.Copy(client, client)
61
-				server.testCtx.Logf("%v bytes echoed back to the client\n", written)
62
-				if err != nil {
59
+				if _, err := io.Copy(client, client); err != nil {
63 60
 					server.testCtx.Logf("can't echo to the client: %v\n", err.Error())
64 61
 				}
65 62
 				client.Close()
... ...
@@ -79,7 +75,6 @@ func (server *UDPEchoServer) Run() {
79 79
 			if err != nil {
80 80
 				return
81 81
 			}
82
-			server.testCtx.Logf("Writing UDP datagram back")
83 82
 			for i := 0; i != read; {
84 83
 				written, err := server.conn.WriteTo(readBuf[i:read], from)
85 84
 				if err != nil {
... ...
@@ -340,7 +340,6 @@ func startEchoServerContainer(t *testing.T, proto string) (*Runtime, *Container,
340 340
 		} else {
341 341
 			t.Fatal(fmt.Errorf("Unknown protocol %v", proto))
342 342
 		}
343
-		t.Log("Trying port", strPort)
344 343
 		container, err = runtime.Create(&Config{
345 344
 			Image:     GetTestImage(runtime).ID,
346 345
 			Cmd:       []string{"sh", "-c", cmd},
... ...
@@ -353,7 +352,7 @@ func startEchoServerContainer(t *testing.T, proto string) (*Runtime, *Container,
353 353
 			nuke(runtime)
354 354
 			t.Fatal(err)
355 355
 		}
356
-		t.Logf("Port %v already in use", strPort)
356
+		t.Logf("Port %v already in use, trying another one", strPort)
357 357
 	}
358 358
 
359 359
 	if err := container.Start(&HostConfig{}); err != nil {