@@ -583,6 +583,78 @@ 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+
622+ public function testReconnectAfterStreamClosesIgnoresInvalidRetryTime ()
623+ {
624+ $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
625+ $ timerReconnect = null ;
626+ $ loop ->expects ($ this ->once ())->method ('addTimer ' )->with (
627+ 3 ,
628+ $ this ->callback (function ($ cb ) use (&$ timerReconnect ) {
629+ $ timerReconnect = $ cb ;
630+ return true ;
631+ })
632+ );
633+
634+ $ deferred = new Deferred ();
635+ $ browser = $ this ->getMockBuilder ('React\Http\Browser ' )->disableOriginalConstructor ()->getMock ();
636+ $ browser ->expects ($ this ->once ())->method ('withRejectErrorResponse ' )->willReturnSelf ();
637+ $ browser ->expects ($ this ->exactly (2 ))->method ('requestStreaming ' )->withConsecutive (
638+ ['GET ' , 'http://example.com ' , ['Accept ' => 'text/event-stream ' , 'Cache-Control ' => 'no-cache ' ]],
639+ ['GET ' , 'http://example.com ' , ['Accept ' => 'text/event-stream ' , 'Cache-Control ' => 'no-cache ' ]]
640+ )->willReturnOnConsecutiveCalls (
641+ $ deferred ->promise (),
642+ new Promise (function () { })
643+ );
644+
645+ $ es = new EventSource ('http://example.com ' , $ browser , $ loop );
646+
647+ $ stream = new ThroughStream ();
648+ $ response = new Response (200 , array ('Content-Type ' => 'text/event-stream ' ), new ReadableBodyStream ($ stream ));
649+ $ deferred ->resolve ($ response );
650+
651+ $ stream ->write ("retry:now \n\n" );
652+ $ stream ->end ();
653+
654+ $ this ->assertNotNull ($ timerReconnect );
655+ $ timerReconnect ();
656+ }
657+
586658 public function setExpectedException ($ exception , $ exceptionMessage = '' , $ exceptionCode = null )
587659 {
588660 if (method_exists ($ this , 'expectException ' )) {
0 commit comments