From 2683b2eb2d2f8f5a1a29eabcb7aefd0e6b0c0809 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Wed, 24 Nov 2021 21:40:59 +0100 Subject: [PATCH] Explicitly close resources, so they don't affect further tests --- test/Driver/StreamSelectDriverTest.php | 31 ++++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/test/Driver/StreamSelectDriverTest.php b/test/Driver/StreamSelectDriverTest.php index f14ea6b..5c3679b 100644 --- a/test/Driver/StreamSelectDriverTest.php +++ b/test/Driver/StreamSelectDriverTest.php @@ -60,21 +60,28 @@ public function testTooLargeFileDescriptorSet(): void $this->expectException(\Exception::class); $this->expectExceptionMessage("You have reached the limits of stream_select(). It has a FD_SETSIZE of 1024, but you have file descriptors numbered at least as high as 2"); - $this->start(function (Driver $loop) use ($sockets) { - $loop->delay(0.1, function () { - // here to provide timeout to stream_select, as the warning is only issued after the system call returns - }); - - foreach ($sockets as [$left, $right]) { - $loop->onReadable($left, function () { - // nothing + try { + $this->start(function (Driver $loop) use ($sockets) { + $loop->delay(0.1, function () { + // here to provide timeout to stream_select, as the warning is only issued after the system call returns }); - $loop->onReadable($right, function () { - // nothing - }); + foreach ($sockets as [$left, $right]) { + $loop->onReadable($left, function () { + // nothing + }); + + $loop->onReadable($right, function () { + // nothing + }); + } + }); + } finally { + foreach ($sockets as [$left, $right]) { + \fclose($left); + \fclose($right); } - }); + } } /**