浏览代码

Merge pull request #10072 from LK4D4/fix_mutable_net_files

Rewrite TestRunMutableNetworkFiles to avoid races
Jessie Frazelle 10 年之前
父节点
当前提交
95fea08f7a
共有 1 个文件被更改,包括 8 次插入13 次删除
  1. 8 13
      integration-cli/docker_cli_run_test.go

+ 8 - 13
integration-cli/docker_cli_run_test.go

@@ -2007,7 +2007,7 @@ func TestRunMutableNetworkFiles(t *testing.T) {
 	for _, fn := range []string{"resolv.conf", "hosts"} {
 		deleteAllContainers()
 
-		content, err := runCommandAndReadContainerFile(fn, exec.Command(dockerBinary, "run", "-d", "--name", "c1", "busybox", "sh", "-c", fmt.Sprintf("echo success >/etc/%s; while true; do sleep 1; done", fn)))
+		content, err := runCommandAndReadContainerFile(fn, exec.Command(dockerBinary, "run", "-d", "--name", "c1", "busybox", "sh", "-c", fmt.Sprintf("echo success >/etc/%s && top", fn)))
 		if err != nil {
 			t.Fatal(err)
 		}
@@ -2016,16 +2016,16 @@ func TestRunMutableNetworkFiles(t *testing.T) {
 			t.Fatal("Content was not what was modified in the container", string(content))
 		}
 
-		out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "c2", "busybox", "sh", "-c", fmt.Sprintf("while true; do cat /etc/%s; sleep 1; done", fn)))
+		out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "c2", "busybox", "top"))
 		if err != nil {
 			t.Fatal(err)
 		}
 
 		contID := strings.TrimSpace(out)
 
-		resolvConfPath := containerStorageFile(contID, fn)
+		netFilePath := containerStorageFile(contID, fn)
 
-		f, err := os.OpenFile(resolvConfPath, os.O_WRONLY|os.O_SYNC|os.O_APPEND, 0644)
+		f, err := os.OpenFile(netFilePath, os.O_WRONLY|os.O_SYNC|os.O_APPEND, 0644)
 		if err != nil {
 			t.Fatal(err)
 		}
@@ -2044,19 +2044,14 @@ func TestRunMutableNetworkFiles(t *testing.T) {
 			f.Close()
 			t.Fatal(err)
 		}
-
 		f.Close()
 
-		time.Sleep(2 * time.Second) // don't race sleep
-
-		out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "logs", "c2"))
+		res, err := exec.Command(dockerBinary, "exec", contID, "cat", "/etc/"+fn).CombinedOutput()
 		if err != nil {
-			t.Fatal(err)
+			t.Fatalf("Output: %s, error: %s", res, err)
 		}
-
-		lines := strings.Split(out, "\n")
-		if strings.TrimSpace(lines[len(lines)-2]) != "success2" {
-			t.Fatalf("Did not find the correct output in /etc/%s: %s %#v", fn, out, lines)
+		if string(res) != "success2\n" {
+			t.Fatalf("Expected content of %s: %q, got: %q", fn, "success2\n", res)
 		}
 	}
 	logDone("run - mutable network files")