Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 0dc9fb1

Browse files
committed
Destruction edge cases
1 parent 427353a commit 0dc9fb1

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/Proxy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use function get_class;
2121
use function is_object;
2222
use function random_bytes;
23+
use function var_export;
2324

2425
final class Proxy extends ProxyList
2526
{
@@ -132,6 +133,8 @@ private function setUpHandlers(): void
132133
private function handleNotify(Notify $notify): void
133134
{
134135
if (! array_key_exists($notify->hash(), $this->instances)) {
136+
var_export($notify);
137+
135138
return;
136139
}
137140

@@ -148,6 +151,8 @@ private function handleNotify(Notify $notify): void
148151
private function handleCall(Call $call): void
149152
{
150153
if (! array_key_exists($call->hash(), $this->instances)) {
154+
var_export($call);
155+
151156
return;
152157
}
153158

tests/ProxyTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)