@@ -207,4 +207,47 @@ public function destructionEdgeCases(): void
207207 );
208208 self ::assertSame (1337 , $ leet );
209209 }
210+
211+ /**
212+ * @test
213+ */
214+ public function destructionLocked (): void
215+ {
216+ $ loop = EventLoopFactory::create ();
217+ $ factory = new Factory ($ loop );
218+ $ registry = new InMemmoryRegistry ();
219+ $ proxy = (new Proxy ($ factory ))->withMetrics ($ registry );
220+ $ limitedPool = $ factory ->limitedPool (13 );
221+ $ registryProxy = $ proxy ->create ($ registry , Registry::class, true );
222+ $ fn = static function (int $ int , WyriHaximus__Metrics_RegistryProxy $ registryProxy , int $ sleep ): int {
223+ sleep ($ sleep );
224+ $ registryProxy ->counter ('counter ' , 'bla bla bla ' , new Label \Name ('name ' ))->counter (new Label ('name ' , 'value ' ))->incr ();
225+
226+ return $ int ;
227+ };
228+
229+ $ promises = [];
230+ foreach (range (0 , 3 ) as $ i ) {
231+ $ promises [] = $ limitedPool ->run ($ fn , [$ i , $ registryProxy , 0 ]);
232+ }
233+
234+ $ leet = $ this ->await (
235+ // @phpstan-ignore-next-line
236+ all ($ promises )->then (static function (array $ v ) use ($ factory ): PromiseInterface {
237+ return new Promise (static function (callable $ resolve ) use ($ v , $ factory ): void {
238+ $ factory ->loop ()->addTimer (3 , static function () use ($ resolve , $ v ): void {
239+ $ resolve ($ v );
240+ });
241+ });
242+ })->then (static function () use ($ fn , $ registryProxy , $ limitedPool ): PromiseInterface {
243+ return $ limitedPool ->run ($ fn , [1337 , $ registryProxy , 20 ]);
244+ })->always (static function () use ($ limitedPool , $ loop ): void {
245+ $ limitedPool ->kill ();
246+ $ loop ->stop ();
247+ }),
248+ $ loop ,
249+ 133
250+ );
251+ self ::assertSame (1337 , $ leet );
252+ }
210253}
0 commit comments