@@ -158,6 +158,39 @@ public function testQueryRejectsIfSendToServerFailsAfterConnection()
158158 throw $ exception ;
159159 }
160160
161+ public function testQueryKeepsPendingIfReadFailsBecauseServerRefusesConnection ()
162+ {
163+ $ socket = null ;
164+ $ callback = null ;
165+ $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
166+ $ loop ->expects ($ this ->once ())->method ('addReadStream ' )->with ($ this ->callback (function ($ ref ) use (&$ socket ) {
167+ $ socket = $ ref ;
168+ return true ;
169+ }), $ this ->callback (function ($ ref ) use (&$ callback ) {
170+ $ callback = $ ref ;
171+ return true ;
172+ }));
173+
174+ $ executor = new UdpTransportExecutor ('0.0.0.0 ' , $ loop );
175+
176+ $ query = new Query ('reactphp.org ' , Message::TYPE_A , Message::CLASS_IN );
177+ $ promise = $ executor ->query ($ query );
178+
179+ $ this ->assertNotNull ($ socket );
180+ $ callback ($ socket );
181+
182+ $ this ->assertInstanceOf ('React\Promise\PromiseInterface ' , $ promise );
183+
184+ $ pending = true ;
185+ $ promise ->then (function () use (&$ pending ) {
186+ $ pending = false ;
187+ }, function () use (&$ pending ) {
188+ $ pending = false ;
189+ });
190+
191+ $ this ->assertTrue ($ pending );
192+ }
193+
161194 /**
162195 * @group internet
163196 */
@@ -177,27 +210,6 @@ public function testQueryRejectsOnCancellation()
177210 $ promise ->then (null , $ this ->expectCallableOnce ());
178211 }
179212
180- public function testQueryKeepsPendingIfServerRejectsNetworkPacket ()
181- {
182- $ loop = Factory::create ();
183-
184- $ executor = new UdpTransportExecutor ('127.0.0.1:1 ' , $ loop );
185-
186- $ query = new Query ('google.com ' , Message::TYPE_A , Message::CLASS_IN );
187-
188- $ wait = true ;
189- $ promise = $ executor ->query ($ query )->then (
190- null ,
191- function ($ e ) use (&$ wait ) {
192- $ wait = false ;
193- throw $ e ;
194- }
195- );
196-
197- \Clue \React \Block \sleep (0.2 , $ loop );
198- $ this ->assertTrue ($ wait );
199- }
200-
201213 public function testQueryKeepsPendingIfServerSendsInvalidMessage ()
202214 {
203215 $ loop = Factory::create ();
0 commit comments