66import static org .hamcrest .Matchers .isEmptyString ;
77import static org .hamcrest .Matchers .not ;
88
9- import java .io .ByteArrayInputStream ;
109import java .io .File ;
11- import java .io .InputStream ;
10+ import java .io .PipedInputStream ;
11+ import java .io .PipedOutputStream ;
1212import java .lang .reflect .Method ;
13- import java .util .concurrent .TimeUnit ;
1413
1514import org .testng .ITestResult ;
1615import org .testng .annotations .AfterMethod ;
@@ -93,8 +92,6 @@ public void attachContainerWithStdin() throws Exception {
9392
9493 dockerClient .startContainerCmd (container .getId ()).exec ();
9594
96- Thread .sleep (SECONDS .toMillis (10 )); //wait bash initialisation
97-
9895 InspectContainerResponse inspectContainerResponse = dockerClient .inspectContainerCmd (container .getId ()).exec ();
9996
10097 assertTrue (inspectContainerResponse .getState ().getRunning ());
@@ -107,15 +104,20 @@ public void onNext(Frame frame) {
107104 }
108105 };
109106
110- InputStream stdin = new ByteArrayInputStream ((snippet + "\n " ).getBytes ());
107+ PipedOutputStream out = new PipedOutputStream ();
108+ PipedInputStream in = new PipedInputStream (out );
111109
112110 dockerClient .attachContainerCmd (container .getId ())
113111 .withStdErr (true )
114112 .withStdOut (true )
115113 .withFollowStream (true )
116- .withStdIn (stdin )
117- .exec (callback )
118- .awaitCompletion (30 , SECONDS );
114+ .withStdIn (in )
115+ .exec (callback );
116+
117+ out .write ((snippet + "\n " ).getBytes ());
118+ out .flush ();
119+
120+ callback .awaitCompletion (15 , SECONDS );
119121 callback .close ();
120122
121123 assertThat (callback .toString (), containsString (snippet ));
0 commit comments