File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,6 +61,39 @@ public function testAddReadStreamIgnoresSecondCallable()
6161 $ this ->tickLoop ($ this ->loop );
6262 }
6363
64+ public function testAddReadStreamReceivesDataFromStreamReference ()
65+ {
66+ $ this ->received = '' ;
67+ $ this ->subAddReadStreamReceivesDataFromStreamReference ();
68+ $ this ->assertEquals ('' , $ this ->received );
69+
70+ $ this ->assertRunFasterThan ($ this ->tickTimeout * 2 );
71+ $ this ->assertEquals ('[hello]X ' , $ this ->received );
72+ }
73+
74+ /**
75+ * Telper for above test. This happens in another helper method to verify
76+ * the loop keep track of assigned stream resources (refcount).
77+ */
78+ private function subAddReadStreamReceivesDataFromStreamReference ()
79+ {
80+ list ($ input , $ output ) = $ this ->createSocketPair ();
81+
82+ fwrite ($ input , 'hello ' );
83+ fclose ($ input );
84+
85+ $ this ->loop ->addReadStream ($ output , function ($ output ) {
86+ $ chunk = fread ($ output , 1024 );
87+ if ($ chunk === '' ) {
88+ $ this ->received .= 'X ' ;
89+ $ this ->loop ->removeReadStream ($ output );
90+ fclose ($ output );
91+ } else {
92+ $ this ->received .= '[ ' . $ chunk . '] ' ;
93+ }
94+ });
95+ }
96+
6497 public function testAddWriteStream ()
6598 {
6699 list ($ input ) = $ this ->createSocketPair ();
You can’t perform that action at this time.
0 commit comments