From 4a151bb6e6a51fb03ace70284d22650e91ab18b5 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 29 Nov 2013 09:11:20 -0800 Subject: [PATCH] Actually test the detach (was not the case before) Upstream-commit: 63d6cbe3e4d6f29c2491b0f1f505ef79b7191d8e Component: engine --- components/engine/commands.go | 6 ++++++ components/engine/integration/commands_test.go | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index db752447f0..24218d284c 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -2394,6 +2394,12 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea if stdout != nil { receiveStdout = utils.Go(func() (err error) { + defer func() { + if in != nil { + in.Close() + } + }() + // When TTY is ON, use regular copy if setRawTerminal { _, err = io.Copy(stdout, br) diff --git a/components/engine/integration/commands_test.go b/components/engine/integration/commands_test.go index f2b14482b2..75d09facb4 100644 --- a/components/engine/integration/commands_test.go +++ b/components/engine/integration/commands_test.go @@ -542,18 +542,18 @@ func TestAttachDetach(t *testing.T) { }) 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 setTimeout(t, "Waiting for CmdAttach timed out", 15*time.Second, func() { <-ch }) + closeWrap(stdin, stdinPipe, stdout, stdoutPipe) + time.Sleep(500 * time.Millisecond) if !container.State.IsRunning() { t.Fatal("The detached container should be still running")