Browse code

Fix race within TestRunDisconnectTty

Guillaume J. Charmes authored on 2013/04/23 03:16:32
Showing 2 changed files
... ...
@@ -979,8 +979,13 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout rcli.DockerConn, args ...s
979 979
 	}
980 980
 	Debugf("Waiting for attach to return\n")
981 981
 	<-attachErr
982
-	container.Wait()
983 982
 	// Expecting I/O pipe error, discarding
983
+
984
+	// If we are in stdinonce mode, wait for the process to end
985
+	// otherwise, simply return
986
+	if config.StdinOnce && !config.Tty {
987
+		container.Wait()
988
+	}
984 989
 	return nil
985 990
 }
986 991
 
... ...
@@ -228,6 +228,21 @@ func TestRunDisconnectTty(t *testing.T) {
228 228
 		close(c1)
229 229
 	}()
230 230
 
231
+	setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() {
232
+		for {
233
+			// Client disconnect after run -i should keep stdin out in TTY mode
234
+			l := runtime.List()
235
+			if len(l) == 1 && l[0].State.Running {
236
+				break
237
+			}
238
+
239
+			time.Sleep(10 * time.Millisecond)
240
+		}
241
+	})
242
+
243
+	// Client disconnect after run -i should keep stdin out in TTY mode
244
+	container := runtime.List()[0]
245
+
231 246
 	setTimeout(t, "Read/Write assertion timed out", 2*time.Second, func() {
232 247
 		if err := assertPipe("hello\n", "hello", stdout, stdinPipe, 15); err != nil {
233 248
 			t.Fatal(err)
... ...
@@ -242,8 +257,6 @@ func TestRunDisconnectTty(t *testing.T) {
242 242
 	// In tty mode, we expect the process to stay alive even after client's stdin closes.
243 243
 	// Do not wait for run to finish
244 244
 
245
-	// Client disconnect after run -i should keep stdin out in TTY mode
246
-	container := runtime.List()[0]
247 245
 	// Give some time to monitor to do his thing
248 246
 	container.WaitTimeout(500 * time.Millisecond)
249 247
 	if !container.State.Running {