浏览代码

Merge pull request #2385 from dotcloud/suppress_even_more_warnings_test

Improve tests again, remove warnings and prevent some mount issues
Michael Crosby 11 年之前
父节点
当前提交
ff567f8729
共有 6 个文件被更改,包括 52 次插入11 次删除
  1. 2 2
      api_test.go
  2. 42 0
      commands_test.go
  3. 6 0
      container.go
  4. 0 1
      container_test.go
  5. 1 6
      network_proxy_test.go
  6. 1 2
      runtime_test.go

+ 2 - 2
api_test.go

@@ -731,7 +731,7 @@ func TestPostContainersRestart(t *testing.T) {
 	container, err := runtime.Create(
 		&Config{
 			Image:     GetTestImage(runtime).ID,
-			Cmd:       []string{"/bin/cat"},
+			Cmd:       []string{"/bin/top"},
 			OpenStdin: true,
 		},
 	)
@@ -837,7 +837,7 @@ func TestPostContainersStop(t *testing.T) {
 	container, err := runtime.Create(
 		&Config{
 			Image:     GetTestImage(runtime).ID,
-			Cmd:       []string{"/bin/cat"},
+			Cmd:       []string{"/bin/top"},
 			OpenStdin: true,
 		},
 	)

+ 42 - 0
commands_test.go

@@ -84,10 +84,24 @@ func TestRunHostname(t *testing.T) {
 		}
 	})
 
+	container := globalRuntime.List()[0]
+
 	setTimeout(t, "CmdRun timed out", 10*time.Second, func() {
 		<-c
+
+		go func() {
+			cli.CmdWait(container.ID)
+		}()
+
+		if _, err := bufio.NewReader(stdout).ReadString('\n'); err != nil {
+			t.Fatal(err)
+		}
 	})
 
+	// Cleanup pipes
+	if err := closeWrap(stdout, stdoutPipe); err != nil {
+		t.Fatal(err)
+	}
 }
 
 // TestRunWorkdir checks that 'docker run -w' correctly sets a custom working directory
@@ -115,10 +129,24 @@ func TestRunWorkdir(t *testing.T) {
 		}
 	})
 
+	container := globalRuntime.List()[0]
+
 	setTimeout(t, "CmdRun timed out", 10*time.Second, func() {
 		<-c
+
+		go func() {
+			cli.CmdWait(container.ID)
+		}()
+
+		if _, err := bufio.NewReader(stdout).ReadString('\n'); err != nil {
+			t.Fatal(err)
+		}
 	})
 
+	// Cleanup pipes
+	if err := closeWrap(stdout, stdoutPipe); err != nil {
+		t.Fatal(err)
+	}
 }
 
 // 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) {
 		}
 	})
 
+	container := globalRuntime.List()[0]
+
 	setTimeout(t, "CmdRun timed out", 5*time.Second, func() {
 		<-c
+
+		go func() {
+			cli.CmdWait(container.ID)
+		}()
+
+		if _, err := bufio.NewReader(stdout).ReadString('\n'); err != nil {
+			t.Fatal(err)
+		}
 	})
 
+	// Cleanup pipes
+	if err := closeWrap(stdout, stdoutPipe); err != nil {
+		t.Fatal(err)
+	}
 }
 
 func TestRunExit(t *testing.T) {

+ 6 - 0
container.go

@@ -1249,6 +1249,12 @@ func (container *Container) Mounted() (bool, error) {
 }
 
 func (container *Container) Unmount() error {
+	if _, err := os.Stat(container.RootfsPath()); err != nil {
+		if os.IsNotExist(err) {
+			return nil
+		}
+		return err
+	}
 	return Unmount(container.RootfsPath())
 }
 

+ 0 - 1
container_test.go

@@ -1593,7 +1593,6 @@ func TestMultipleVolumesFrom(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	t.Log(container3.Volumes)
 	if container3.Volumes["/test"] != container.Volumes["/test"] {
 		t.Fail()
 	}

+ 1 - 6
network_proxy_test.go

@@ -44,7 +44,6 @@ func NewEchoServer(t *testing.T, proto, address string) EchoServer {
 		}
 		server = &UDPEchoServer{conn: socket, testCtx: t}
 	}
-	t.Logf("EchoServer listening on %v/%v\n", proto, server.LocalAddr().String())
 	return server
 }
 
@@ -56,10 +55,7 @@ func (server *TCPEchoServer) Run() {
 				return
 			}
 			go func(client net.Conn) {
-				server.testCtx.Logf("TCP client accepted on the EchoServer\n")
-				written, err := io.Copy(client, client)
-				server.testCtx.Logf("%v bytes echoed back to the client\n", written)
-				if err != nil {
+				if _, err := io.Copy(client, client); err != nil {
 					server.testCtx.Logf("can't echo to the client: %v\n", err.Error())
 				}
 				client.Close()
@@ -79,7 +75,6 @@ func (server *UDPEchoServer) Run() {
 			if err != nil {
 				return
 			}
-			server.testCtx.Logf("Writing UDP datagram back")
 			for i := 0; i != read; {
 				written, err := server.conn.WriteTo(readBuf[i:read], from)
 				if err != nil {

+ 1 - 2
runtime_test.go

@@ -340,7 +340,6 @@ func startEchoServerContainer(t *testing.T, proto string) (*Runtime, *Container,
 		} else {
 			t.Fatal(fmt.Errorf("Unknown protocol %v", proto))
 		}
-		t.Log("Trying port", strPort)
 		container, err = runtime.Create(&Config{
 			Image:     GetTestImage(runtime).ID,
 			Cmd:       []string{"sh", "-c", cmd},
@@ -353,7 +352,7 @@ func startEchoServerContainer(t *testing.T, proto string) (*Runtime, *Container,
 			nuke(runtime)
 			t.Fatal(err)
 		}
-		t.Logf("Port %v already in use", strPort)
+		t.Logf("Port %v already in use, trying another one", strPort)
 	}
 
 	if err := container.Start(&HostConfig{}); err != nil {