mirror of https://github.com/docker/docs.git
Fix behavior of tty tests
This commit is contained in:
parent
2ec1146679
commit
86c00be180
|
@ -337,7 +337,8 @@ func TestRunDisconnect(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expected behaviour: the process dies when the client disconnects
|
// Expected behaviour: the process stay alive when the client disconnects
|
||||||
|
// but the client detaches.
|
||||||
func TestRunDisconnectTty(t *testing.T) {
|
func TestRunDisconnectTty(t *testing.T) {
|
||||||
|
|
||||||
stdin, stdinPipe := io.Pipe()
|
stdin, stdinPipe := io.Pipe()
|
||||||
|
@ -348,29 +349,20 @@ func TestRunDisconnectTty(t *testing.T) {
|
||||||
|
|
||||||
c1 := make(chan struct{})
|
c1 := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
|
defer close(c1)
|
||||||
// We're simulating a disconnect so the return value doesn't matter. What matters is the
|
// We're simulating a disconnect so the return value doesn't matter. What matters is the
|
||||||
// fact that CmdRun returns.
|
// fact that CmdRun returns.
|
||||||
if err := cli.CmdRun("-i", "-t", unitTestImageID, "/bin/cat"); err != nil {
|
if err := cli.CmdRun("-i", "-t", unitTestImageID, "/bin/cat"); err != nil {
|
||||||
utils.Debugf("Error CmdRun: %s", err)
|
utils.Debugf("Error CmdRun: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
close(c1)
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
setTimeout(t, "Waiting for the container to be started timed out", 10*time.Second, func() {
|
container := waitContainerStart(t, 10*time.Second)
|
||||||
for {
|
|
||||||
// Client disconnect after run -i should keep stdin out in TTY mode
|
state := setRaw(t, container)
|
||||||
l := globalRuntime.List()
|
defer unsetRaw(t, container, state)
|
||||||
if len(l) == 1 && l[0].State.IsRunning() {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Client disconnect after run -i should keep stdin out in TTY mode
|
// Client disconnect after run -i should keep stdin out in TTY mode
|
||||||
container := globalRuntime.List()[0]
|
|
||||||
|
|
||||||
setTimeout(t, "Read/Write assertion timed out", 2*time.Second, func() {
|
setTimeout(t, "Read/Write assertion timed out", 2*time.Second, func() {
|
||||||
if err := assertPipe("hello\n", "hello", stdout, stdinPipe, 150); err != nil {
|
if err := assertPipe("hello\n", "hello", stdout, stdinPipe, 150); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -382,8 +374,12 @@ func TestRunDisconnectTty(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wait for CmdRun to return
|
||||||
|
setTimeout(t, "Waiting for CmdRun timed out", 5*time.Second, func() {
|
||||||
|
<-c1
|
||||||
|
})
|
||||||
|
|
||||||
// In tty mode, we expect the process to stay alive even after client's stdin closes.
|
// In tty mode, we expect the process to stay alive even after client's stdin closes.
|
||||||
// Do not wait for run to finish
|
|
||||||
|
|
||||||
// Give some time to monitor to do his thing
|
// Give some time to monitor to do his thing
|
||||||
container.WaitTimeout(500 * time.Millisecond)
|
container.WaitTimeout(500 * time.Millisecond)
|
||||||
|
@ -473,27 +469,28 @@ func TestRunDetach(t *testing.T) {
|
||||||
cli.CmdRun("-i", "-t", unitTestImageID, "cat")
|
cli.CmdRun("-i", "-t", unitTestImageID, "cat")
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
container := waitContainerStart(t, 10*time.Second)
|
||||||
|
|
||||||
|
state := setRaw(t, container)
|
||||||
|
defer unsetRaw(t, container, state)
|
||||||
|
|
||||||
setTimeout(t, "First read/write assertion timed out", 2*time.Second, func() {
|
setTimeout(t, "First read/write assertion timed out", 2*time.Second, func() {
|
||||||
if err := assertPipe("hello\n", "hello", stdout, stdinPipe, 150); err != nil {
|
if err := assertPipe("hello\n", "hello", stdout, stdinPipe, 150); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
container := globalRuntime.List()[0]
|
|
||||||
|
|
||||||
setTimeout(t, "Escape sequence timeout", 5*time.Second, func() {
|
setTimeout(t, "Escape sequence timeout", 5*time.Second, func() {
|
||||||
stdinPipe.Write([]byte{16, 17})
|
stdinPipe.Write([]byte{16})
|
||||||
if err := stdinPipe.Close(); err != nil {
|
time.Sleep(100 * time.Millisecond)
|
||||||
t.Fatal(err)
|
stdinPipe.Write([]byte{17})
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
closeWrap(stdin, stdinPipe, stdout, stdoutPipe)
|
|
||||||
|
|
||||||
// wait for CmdRun to return
|
// wait for CmdRun to return
|
||||||
setTimeout(t, "Waiting for CmdRun timed out", 15*time.Second, func() {
|
setTimeout(t, "Waiting for CmdRun 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() {
|
||||||
|
@ -594,6 +591,7 @@ func TestAttachDetachTruncatedID(t *testing.T) {
|
||||||
cli := docker.NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr)
|
cli := docker.NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr)
|
||||||
defer cleanup(globalEngine, t)
|
defer cleanup(globalEngine, t)
|
||||||
|
|
||||||
|
// Discard the CmdRun output
|
||||||
go stdout.Read(make([]byte, 1024))
|
go stdout.Read(make([]byte, 1024))
|
||||||
setTimeout(t, "Starting container timed out", 2*time.Second, func() {
|
setTimeout(t, "Starting container timed out", 2*time.Second, func() {
|
||||||
if err := cli.CmdRun("-i", "-t", "-d", unitTestImageID, "cat"); err != nil {
|
if err := cli.CmdRun("-i", "-t", "-d", unitTestImageID, "cat"); err != nil {
|
||||||
|
@ -759,6 +757,7 @@ func TestRunAutoRemove(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCmdLogs(t *testing.T) {
|
func TestCmdLogs(t *testing.T) {
|
||||||
|
t.Skip("Test not impemented")
|
||||||
cli := docker.NewDockerCli(nil, ioutil.Discard, ioutil.Discard, testDaemonProto, testDaemonAddr)
|
cli := docker.NewDockerCli(nil, ioutil.Discard, ioutil.Discard, testDaemonProto, testDaemonAddr)
|
||||||
defer cleanup(globalEngine, t)
|
defer cleanup(globalEngine, t)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue