|
@@ -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) {
|
|
|
|
|
|
stdin, stdinPipe := io.Pipe()
|
|
@@ -348,29 +349,20 @@ func TestRunDisconnectTty(t *testing.T) {
|
|
|
|
|
|
c1 := make(chan struct{})
|
|
|
go func() {
|
|
|
+ defer close(c1)
|
|
|
// We're simulating a disconnect so the return value doesn't matter. What matters is the
|
|
|
// fact that CmdRun returns.
|
|
|
if err := cli.CmdRun("-i", "-t", unitTestImageID, "/bin/cat"); err != nil {
|
|
|
utils.Debugf("Error CmdRun: %s", err)
|
|
|
}
|
|
|
-
|
|
|
- close(c1)
|
|
|
}()
|
|
|
|
|
|
- setTimeout(t, "Waiting for the container to be started timed out", 10*time.Second, func() {
|
|
|
- for {
|
|
|
- // Client disconnect after run -i should keep stdin out in TTY mode
|
|
|
- l := globalRuntime.List()
|
|
|
- if len(l) == 1 && l[0].State.IsRunning() {
|
|
|
- break
|
|
|
- }
|
|
|
- time.Sleep(10 * time.Millisecond)
|
|
|
- }
|
|
|
- })
|
|
|
+ container := waitContainerStart(t, 10*time.Second)
|
|
|
|
|
|
- // Client disconnect after run -i should keep stdin out in TTY mode
|
|
|
- container := globalRuntime.List()[0]
|
|
|
+ state := setRaw(t, container)
|
|
|
+ defer unsetRaw(t, container, state)
|
|
|
|
|
|
+ // Client disconnect after run -i should keep stdin out in TTY mode
|
|
|
setTimeout(t, "Read/Write assertion timed out", 2*time.Second, func() {
|
|
|
if err := assertPipe("hello\n", "hello", stdout, stdinPipe, 150); err != nil {
|
|
|
t.Fatal(err)
|
|
@@ -382,8 +374,12 @@ func TestRunDisconnectTty(t *testing.T) {
|
|
|
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.
|
|
|
- // Do not wait for run to finish
|
|
|
|
|
|
// Give some time to monitor to do his thing
|
|
|
container.WaitTimeout(500 * time.Millisecond)
|
|
@@ -473,27 +469,28 @@ func TestRunDetach(t *testing.T) {
|
|
|
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() {
|
|
|
if err := assertPipe("hello\n", "hello", stdout, stdinPipe, 150); err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- container := globalRuntime.List()[0]
|
|
|
-
|
|
|
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 CmdRun timed out", 15*time.Second, func() {
|
|
|
<-ch
|
|
|
})
|
|
|
+ closeWrap(stdin, stdinPipe, stdout, stdoutPipe)
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
if !container.State.IsRunning() {
|
|
@@ -594,6 +591,7 @@ func TestAttachDetachTruncatedID(t *testing.T) {
|
|
|
cli := docker.NewDockerCli(stdin, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr)
|
|
|
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 {
|
|
@@ -759,6 +757,7 @@ func TestRunAutoRemove(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestCmdLogs(t *testing.T) {
|
|
|
+ t.Skip("Test not impemented")
|
|
|
cli := docker.NewDockerCli(nil, ioutil.Discard, ioutil.Discard, testDaemonProto, testDaemonAddr)
|
|
|
defer cleanup(globalEngine, t)
|
|
|
|