44
55namespace Spiral \RoadRunner \Tests \Http \Feature ;
66
7+ use Exception ;
78use PHPUnit \Framework \TestCase ;
89use Spiral \Goridge \SocketRelay ;
910use Spiral \RoadRunner \Http \Exception \StreamStoppedException ;
1011use Spiral \RoadRunner \Http \HttpWorker ;
12+ use Spiral \RoadRunner \Message \Command \GetProcessId ;
1113use Spiral \RoadRunner \Payload ;
1214use Spiral \RoadRunner \Tests \Http \Server \Command \BaseCommand ;
1315use Spiral \RoadRunner \Tests \Http \Server \Command \StreamStop ;
@@ -94,10 +96,31 @@ public function testStopStreamResponse(): void
9496 self ::assertSame (\implode ("\n" , ['Hel ' , 'lo, ' ]), \trim (ServerRunner::getBuffer ()));
9597 }
9698
99+ public function testExceptionInGenerator (): void
100+ {
101+ $ httpWorker = $ this ->makeHttpWorker ();
102+
103+ // Flush buffer
104+ ServerRunner::getBuffer ();
105+
106+ $ httpWorker ->respond (
107+ 200 ,
108+ (function () {
109+ yield 'Hel ' ;
110+ yield 'lo, ' ;
111+ throw new Exception ('test ' );
112+ })(),
113+ );
114+
115+
116+ \usleep (100_000 );
117+ self ::assertSame (\implode ("\n" , ['Hel ' , 'lo, ' ]), \trim (ServerRunner::getBuffer ()));
118+ }
119+
97120 /**
98121 * StopStream should be ignored if stream is already ended.
99122 * Commented because doesn't pass in CI
100- * todo: check after RoadRunner Stream Response release
123+ */
101124 public function testStopStreamAfterStreamEnd (): void
102125 {
103126 $ httpWorker = $ this ->makeHttpWorker ();
@@ -116,11 +139,14 @@ public function testStopStreamAfterStreamEnd(): void
116139 $ this ->assertFalse ($ this ->getWorker ()->hasPayload (\Spiral \RoadRunner \Message \Command \StreamStop::class));
117140 $ this ->sendCommand (new StreamStop ());
118141 \usleep (200_000 );
119- self:: assertSame(\implode("\n", ['Hello', 'World!']), \trim(ServerRunner::getBuffer()));
142+ $ this -> assertSame (\implode ("\n" , ['Hello ' , 'World! ' ]), \trim (ServerRunner::getBuffer ()));
120143 $ this ->assertTrue ($ this ->getWorker ()->hasPayload (\Spiral \RoadRunner \Message \Command \StreamStop::class));
144+
145+ $ this ->getWorker ()->getPayload (\Spiral \RoadRunner \Message \Command \StreamStop::class);
146+ $ this ->getWorker ()->getPayload (GetProcessId::class);
147+
121148 $ this ->assertFalse ($ this ->getWorker ()->hasPayload ());
122149 }
123- */
124150
125151 private function getRelay (): SocketRelay
126152 {
0 commit comments