@@ -266,6 +266,45 @@ public function testStreamMultipleChunks(): void
266266 $ client ->streamText ($ stream );
267267 }
268268
269+ public function testStreamWithInterleavedControlFrames (): void
270+ {
271+ $ packets = \array_map (fn (string $ packet ) => [$ packet ], [
272+ compile (WebsocketFrameType::Text, false , false , 'chunk1 ' ),
273+ compile (WebsocketFrameType::Continuation, false , false , 'chunk2 ' ),
274+ compile (WebsocketFrameType::Ping, false , true , "1 " ),
275+ compile (WebsocketFrameType::Continuation, false , false , 'chunk3 ' ),
276+ compile (WebsocketFrameType::Ping, false , true , "2 " ),
277+ compile (WebsocketFrameType::Continuation, false , true , 'chunk4 ' ),
278+ ]);
279+
280+ $ socket = $ this ->createSocket ();
281+ $ future = new DeferredFuture ();
282+ $ socket ->expects ($ this ->any ())->method ("read " )->willReturnCallback (function () use ($ future ) {
283+ $ future ->getFuture ()->await ();
284+ });
285+ $ socket ->expects ($ this ->atLeastOnce ())
286+ ->method ('write ' )
287+ ->withConsecutive (...$ packets );
288+
289+ $ client = $ this ->createClient ($ socket , frameSplitThreshold: 6 );
290+
291+ $ stream = new ReadableIterableStream ((function () use ($ client ) {
292+ yield 'chunk1 ' ;
293+ yield 'chunk2 ' ;
294+ yield '' ;
295+ $ client ->ping ();
296+ yield 'chunk3 ' ;
297+ yield '' ;
298+ $ client ->ping ();
299+ yield 'chunk4 ' ;
300+ })());
301+
302+ $ client ->streamText ($ stream );
303+
304+ $ future ->complete ();
305+ $ client ->close ();
306+ }
307+
269308 public function testSendWithFailedSocket (): void
270309 {
271310 $ socket = $ this ->createSocket ();
0 commit comments