@@ -583,6 +583,42 @@ public function testReconnectAfterStreamClosesUsesLastEventIdFromParsedEventStre
583583 $ timerReconnect ();
584584 }
585585
586+ public function testReconnectAfterStreamClosesUsesSpecifiedRetryTime ()
587+ {
588+ $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
589+ $ timerReconnect = null ;
590+ $ loop ->expects ($ this ->once ())->method ('addTimer ' )->with (
591+ 2.543 ,
592+ $ this ->callback (function ($ cb ) use (&$ timerReconnect ) {
593+ $ timerReconnect = $ cb ;
594+ return true ;
595+ })
596+ );
597+
598+ $ deferred = new Deferred ();
599+ $ browser = $ this ->getMockBuilder ('React\Http\Browser ' )->disableOriginalConstructor ()->getMock ();
600+ $ browser ->expects ($ this ->once ())->method ('withRejectErrorResponse ' )->willReturnSelf ();
601+ $ browser ->expects ($ this ->exactly (2 ))->method ('requestStreaming ' )->withConsecutive (
602+ ['GET ' , 'http://example.com ' , ['Accept ' => 'text/event-stream ' , 'Cache-Control ' => 'no-cache ' ]],
603+ ['GET ' , 'http://example.com ' , ['Accept ' => 'text/event-stream ' , 'Cache-Control ' => 'no-cache ' ]]
604+ )->willReturnOnConsecutiveCalls (
605+ $ deferred ->promise (),
606+ new Promise (function () { })
607+ );
608+
609+ $ es = new EventSource ('http://example.com ' , $ browser , $ loop );
610+
611+ $ stream = new ThroughStream ();
612+ $ response = new Response (200 , array ('Content-Type ' => 'text/event-stream ' ), new ReadableBodyStream ($ stream ));
613+ $ deferred ->resolve ($ response );
614+
615+ $ stream ->write ("retry:2543 \n\n" );
616+ $ stream ->end ();
617+
618+ $ this ->assertNotNull ($ timerReconnect );
619+ $ timerReconnect ();
620+ }
621+
586622 public function setExpectedException ($ exception , $ exceptionMessage = '' , $ exceptionCode = null )
587623 {
588624 if (method_exists ($ this , 'expectException ' )) {
0 commit comments