@@ -36,9 +36,9 @@ private function spawnHost(int $port, bool $autoPong = true, bool $sendControl =
3636 return [$ proc , $ pipes ];
3737 }
3838
39- private function readEvents ($ pipe , float $ timeout = 4.0 , $ errPipe = null ): array
39+ private function readEvents ($ pipe , float $ timeout = 4.0 , $ errPipe = null , array $ seed = [] ): array
4040 {
41- $ events = [] ;
41+ $ events = $ seed ;
4242 $ deadline = microtime (true ) + $ timeout ;
4343 while (microtime (true ) < $ deadline ) {
4444 $ data = stream_get_contents ($ pipe );
@@ -104,8 +104,8 @@ public function testHandshakeBufferingAndDropNotice(): void
104104 {
105105 $ port = 9891 ;
106106 [$ proc , $ pipes ] = $ this ->spawnHost ($ port );
107- sleep ( 1 ); // allow server to start
108-
107+ $ events = $ this -> readEvents ( $ pipes [ 1 ], 4.0 , $ pipes [ 2 ] ); // wait for host listening
108+
109109 $ cfg = new BridgeConfig ("ws://127.0.0.1: {$ port }" , 'dev-secret ' , null , ['console ' , 'error ' ], 15000 , 30000 , 1000 , 30000 , 3 );
110110 $ client = new Client ($ cfg );
111111
@@ -116,7 +116,7 @@ public function testHandshakeBufferingAndDropNotice(): void
116116 $ pid = $ this ->forkClient ($ client , 2 );
117117 $ this ->waitForChild ($ pid , 5 );
118118
119- $ events = $ this ->readEvents ($ pipes [1 ], 4.0 , $ pipes [2 ]);
119+ $ events = $ this ->readEvents ($ pipes [1 ], 4.0 , $ pipes [2 ], $ events );
120120 proc_terminate ($ proc );
121121
122122 $ recv = array_values (array_filter (array_map (fn ($ e ) => $ e ['msg ' ] ?? null , $ events )));
@@ -142,7 +142,7 @@ public function testControlRoundTrip(): void
142142 {
143143 $ port = 9892 ;
144144 [$ proc , $ pipes ] = $ this ->spawnHost ($ port , true , true );
145- sleep ( 1 );
145+ $ events = $ this -> readEvents ( $ pipes [ 1 ], 4.0 , $ pipes [ 2 ] );
146146
147147 $ cfg = new BridgeConfig ("ws://127.0.0.1: {$ port }" , 'dev-secret ' );
148148 $ client = new Client ($ cfg );
@@ -156,7 +156,7 @@ public function testControlRoundTrip(): void
156156 $ pid = $ this ->forkClient ($ client , 2 );
157157 $ this ->waitForChild ($ pid , 5 );
158158
159- $ events = $ this ->readEvents ($ pipes [1 ], 4.0 , $ pipes [2 ]);
159+ $ events = $ this ->readEvents ($ pipes [1 ], 4.0 , $ pipes [2 ], $ events );
160160 proc_terminate ($ proc );
161161
162162 $ controlResult = null ;
@@ -174,15 +174,15 @@ public function testHeartbeatReconnect(): void
174174 {
175175 $ port = 9893 ;
176176 [$ proc , $ pipes ] = $ this ->spawnHost ($ port , false , false );
177- sleep ( 1 );
177+ $ events = $ this -> readEvents ( $ pipes [ 1 ], 4.0 , $ pipes [ 2 ] );
178178
179179 $ cfg = new BridgeConfig ("ws://127.0.0.1: {$ port }" , 'dev-secret ' , null , ['console ' , 'error ' ], 50 , 120 , 50 , 200 , 10 );
180180 $ client = new Client ($ cfg );
181181
182182 $ pid = $ this ->forkClient ($ client , 3 );
183183 $ this ->waitForChild ($ pid , 6 );
184184
185- $ events = $ this ->readEvents ($ pipes [1 ], 4.0 , $ pipes [2 ]);
185+ $ events = $ this ->readEvents ($ pipes [1 ], 4.0 , $ pipes [2 ], $ events );
186186 proc_terminate ($ proc );
187187
188188 $ recv = array_values (array_filter (array_map (fn ($ e ) => $ e ['msg ' ] ?? null , $ events )));
0 commit comments