浏览代码

Merge pull request #25 from tiborvass/3960-add-file-hangs

adding test for hanging ADD src .
Michael Crosby 11 年之前
父节点
当前提交
04e357d09f

+ 2 - 0
integration-cli/build_tests/TestAdd/SingleFileToWorkdir/Dockerfile

@@ -0,0 +1,2 @@
+FROM busybox
+ADD test_file .

+ 37 - 0
integration-cli/docker_cli_build_test.go

@@ -7,6 +7,7 @@ import (
 	"path/filepath"
 	"path/filepath"
 	"strings"
 	"strings"
 	"testing"
 	"testing"
+	"time"
 )
 )
 
 
 func TestBuildCacheADD(t *testing.T) {
 func TestBuildCacheADD(t *testing.T) {
@@ -77,6 +78,42 @@ func TestAddSingleFileToRoot(t *testing.T) {
 	logDone("build - add single file to root")
 	logDone("build - add single file to root")
 }
 }
 
 
+// Issue #3960: "ADD src ." hangs
+func TestAddSingleFileToWorkdir(t *testing.T) {
+	buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd", "SingleFileToWorkdir")
+	f, err := os.OpenFile(filepath.Join(buildDirectory, "test_file"), os.O_CREATE, 0644)
+	if err != nil {
+		t.Fatal(err)
+	}
+	f.Close()
+	buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", ".")
+	buildCmd.Dir = buildDirectory
+	done := make(chan error)
+	go func() {
+		out, exitCode, err := runCommandWithOutput(buildCmd)
+		if err != nil || exitCode != 0 {
+			done <- fmt.Errorf("build failed to complete: %s %v", out, err)
+			return
+		}
+		done <- nil
+	}()
+	select {
+	case <-time.After(5 * time.Second):
+		if err := buildCmd.Process.Kill(); err != nil {
+			fmt.Printf("could not kill build (pid=%d): %v\n", buildCmd.Process.Pid, err)
+		}
+		t.Fatal("build timed out")
+	case err := <-done:
+		if err != nil {
+			t.Fatal(err)
+		}
+	}
+
+	deleteImages("testaddimg")
+
+	logDone("build - add single file to workdir")
+}
+
 func TestAddSingleFileToExistDir(t *testing.T) {
 func TestAddSingleFileToExistDir(t *testing.T) {
 	buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd")
 	buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd")
 	buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", "SingleFileToExistDir")
 	buildCmd := exec.Command(dockerBinary, "build", "-t", "testaddimg", "SingleFileToExistDir")