|
@@ -12,7 +12,6 @@ import (
|
|
"github.com/Sirupsen/logrus"
|
|
"github.com/Sirupsen/logrus"
|
|
"github.com/docker/docker/api/client"
|
|
"github.com/docker/docker/api/client"
|
|
"github.com/docker/docker/daemon"
|
|
"github.com/docker/docker/daemon"
|
|
- "github.com/docker/docker/pkg/stringid"
|
|
|
|
"github.com/docker/docker/pkg/term"
|
|
"github.com/docker/docker/pkg/term"
|
|
"github.com/kr/pty"
|
|
"github.com/kr/pty"
|
|
)
|
|
)
|
|
@@ -113,78 +112,6 @@ func assertPipe(input, output string, r io.Reader, w io.Writer, count int) error
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-// TestAttachDetachTruncatedID checks that attach in tty mode can be detached
|
|
|
|
-func TestAttachDetachTruncatedID(t *testing.T) {
|
|
|
|
- stdout, stdoutPipe := io.Pipe()
|
|
|
|
- cpty, tty, err := pty.Open()
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- cli := client.NewDockerCli(tty, stdoutPipe, ioutil.Discard, "", testDaemonProto, testDaemonAddr, nil)
|
|
|
|
- defer cleanup(globalEngine, t)
|
|
|
|
-
|
|
|
|
- // Discard the CmdRun output
|
|
|
|
- go stdout.Read(make([]byte, 1024))
|
|
|
|
- setTimeout(t, "Starting container timed out", 2*time.Second, func() {
|
|
|
|
- if err := cli.CmdRun("-i", "-t", "-d", unitTestImageID, "cat"); err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- container := waitContainerStart(t, 10*time.Second)
|
|
|
|
-
|
|
|
|
- state := setRaw(t, container)
|
|
|
|
- defer unsetRaw(t, container, state)
|
|
|
|
-
|
|
|
|
- stdout, stdoutPipe = io.Pipe()
|
|
|
|
- cpty, tty, err = pty.Open()
|
|
|
|
- if err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- cli = client.NewDockerCli(tty, stdoutPipe, ioutil.Discard, "", testDaemonProto, testDaemonAddr, nil)
|
|
|
|
-
|
|
|
|
- ch := make(chan struct{})
|
|
|
|
- go func() {
|
|
|
|
- defer close(ch)
|
|
|
|
- if err := cli.CmdAttach(stringid.TruncateID(container.ID)); err != nil {
|
|
|
|
- if err != io.ErrClosedPipe {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }()
|
|
|
|
-
|
|
|
|
- setTimeout(t, "First read/write assertion timed out", 2*time.Second, func() {
|
|
|
|
- if err := assertPipe("hello\n", "hello", stdout, cpty, 150); err != nil {
|
|
|
|
- if err != io.ErrClosedPipe {
|
|
|
|
- t.Fatal(err)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- setTimeout(t, "Escape sequence timeout", 5*time.Second, func() {
|
|
|
|
- cpty.Write([]byte{16})
|
|
|
|
- time.Sleep(100 * time.Millisecond)
|
|
|
|
- cpty.Write([]byte{17})
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- // wait for CmdRun to return
|
|
|
|
- setTimeout(t, "Waiting for CmdAttach timed out", 15*time.Second, func() {
|
|
|
|
- <-ch
|
|
|
|
- })
|
|
|
|
- closeWrap(cpty, stdout, stdoutPipe)
|
|
|
|
-
|
|
|
|
- time.Sleep(500 * time.Millisecond)
|
|
|
|
- if !container.IsRunning() {
|
|
|
|
- t.Fatal("The detached container should be still running")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- setTimeout(t, "Waiting for container to die timedout", 5*time.Second, func() {
|
|
|
|
- container.Kill()
|
|
|
|
- })
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
// Expected behaviour, the process stays alive when the client disconnects
|
|
// Expected behaviour, the process stays alive when the client disconnects
|
|
func TestAttachDisconnect(t *testing.T) {
|
|
func TestAttachDisconnect(t *testing.T) {
|
|
stdout, stdoutPipe := io.Pipe()
|
|
stdout, stdoutPipe := io.Pipe()
|