Skip to content

Commit 566f5d7

Browse files
committed
Add suspension memory leak test
1 parent f8c96fe commit 566f5d7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/EventLoopTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,34 @@ public function testSuspensionWithinCallback(): void
199199
}
200200

201201
public function testSuspensionWithinCallbackGarbageCollection(): void
202+
{
203+
$memory = 0;
204+
$i = 0;
205+
206+
EventLoop::repeat(0.001, static function (string $id) use (&$memory, &$i) {
207+
$suspension = EventLoop::getSuspension();
208+
EventLoop::defer(static fn () => $suspension->resume());
209+
$suspension->suspend();
210+
211+
if (++$i % 250 === 0) {
212+
\gc_collect_cycles();
213+
214+
if ($memory > 0) {
215+
self::assertSame($memory, \memory_get_usage());
216+
}
217+
218+
$memory = \memory_get_usage();
219+
}
220+
221+
if ($i === 10000) {
222+
EventLoop::cancel($id);
223+
}
224+
});
225+
226+
EventLoop::run();
227+
}
228+
229+
public function testSuspensionWithinCallbackGarbageCollectionSuspended(): void
202230
{
203231
EventLoop::defer(static function () use (&$finally): void {
204232
$suspension = EventLoop::getSuspension();

0 commit comments

Comments
 (0)