@@ -169,4 +169,44 @@ public function metricsDestructionTesting(): void
169169 (int ) explode ("\n" , explode ('react_parallel_object_proxy_destruct_total{class="WyriHaximus\Metrics\InMemory\Registry",interface="WyriHaximus\Metrics\Registry"} ' , $ txt )[1 ])[0 ]
170170 );
171171 }
172+
173+ /**
174+ * @test
175+ */
176+ public function destructionEdgeCases (): void
177+ {
178+ $ loop = EventLoopFactory::create ();
179+ $ factory = new Factory ($ loop );
180+ $ registry = new InMemmoryRegistry ();
181+ $ proxy = (new Proxy ($ factory ))->withMetrics ($ registry );
182+ $ limitedPool = $ factory ->limitedPool (1 );
183+ $ registryProxy = $ proxy ->create ($ registry , Registry::class);
184+ $ fn = static function (int $ int , Registry $ registryProxy ): int {
185+ $ registryProxy ->counter ('counter ' , 'bla bla bla ' , new Label \Name ('name ' ))->counter (new Label ('name ' , 'value ' ))->incr ();
186+
187+ return $ int ;
188+ };
189+
190+ $ promises = [];
191+ foreach (range (0 , 3 ) as $ i ) {
192+ $ promises [] = $ limitedPool ->run ($ fn , [$ i , $ registryProxy ]);
193+ }
194+
195+ $ leet = $ this ->await (
196+ // @phpstan-ignore-next-line
197+ all ($ promises )->then (static function (array $ v ) use ($ factory ): PromiseInterface {
198+ return new Promise (static function (callable $ resolve ) use ($ v , $ factory ): void {
199+ $ factory ->loop ()->addTimer (20 , static function () use ($ resolve , $ v ): void {
200+ $ resolve ($ v );
201+ });
202+ });
203+ })->then (static function () use ($ fn , $ registryProxy , $ limitedPool ): PromiseInterface {
204+ return $ limitedPool ->run ($ fn , [1337 , $ registryProxy ]);
205+ })->always (static function () use ($ limitedPool ): void {
206+ $ limitedPool ->close ();
207+ }),
208+ $ loop
209+ );
210+ self ::assertSame (1337 , $ leet );
211+ }
172212}
0 commit comments