Browse Source

Actually test the detach (was not the case before)

Guillaume J. Charmes 11 năm trước cách đây
mục cha
commit
63d6cbe3e4
2 tập tin đã thay đổi với 11 bổ sung5 xóa
  1. 6 0
      commands.go
  2. 5 5
      integration/commands_test.go

+ 6 - 0
commands.go

@@ -2394,6 +2394,12 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea
 
 
 	if stdout != nil {
 	if stdout != nil {
 		receiveStdout = utils.Go(func() (err error) {
 		receiveStdout = utils.Go(func() (err error) {
+			defer func() {
+				if in != nil {
+					in.Close()
+				}
+			}()
+
 			// When TTY is ON, use regular copy
 			// When TTY is ON, use regular copy
 			if setRawTerminal {
 			if setRawTerminal {
 				_, err = io.Copy(stdout, br)
 				_, err = io.Copy(stdout, br)

+ 5 - 5
integration/commands_test.go

@@ -542,18 +542,18 @@ func TestAttachDetach(t *testing.T) {
 	})
 	})
 
 
 	setTimeout(t, "Escape sequence timeout", 5*time.Second, func() {
 	setTimeout(t, "Escape sequence timeout", 5*time.Second, func() {
-		stdinPipe.Write([]byte{16, 17})
-		if err := stdinPipe.Close(); err != nil {
-			t.Fatal(err)
-		}
+		stdinPipe.Write([]byte{16})
+		time.Sleep(100 * time.Millisecond)
+		stdinPipe.Write([]byte{17})
 	})
 	})
-	closeWrap(stdin, stdinPipe, stdout, stdoutPipe)
 
 
 	// wait for CmdRun to return
 	// wait for CmdRun to return
 	setTimeout(t, "Waiting for CmdAttach timed out", 15*time.Second, func() {
 	setTimeout(t, "Waiting for CmdAttach timed out", 15*time.Second, func() {
 		<-ch
 		<-ch
 	})
 	})
 
 
+	closeWrap(stdin, stdinPipe, stdout, stdoutPipe)
+
 	time.Sleep(500 * time.Millisecond)
 	time.Sleep(500 * time.Millisecond)
 	if !container.State.IsRunning() {
 	if !container.State.IsRunning() {
 		t.Fatal("The detached container should be still running")
 		t.Fatal("The detached container should be still running")