From acf64a4c1e0797a9010013a8c6b51fe2d1468f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sun, 7 Nov 2021 15:33:03 +0100 Subject: [PATCH 1/2] Fix failing test between PHP 7.4.0 and PHP 7.4.7 --- tests/FunctionalFactoryTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/FunctionalFactoryTest.php b/tests/FunctionalFactoryTest.php index 0a3ee8a..4ea86a9 100644 --- a/tests/FunctionalFactoryTest.php +++ b/tests/FunctionalFactoryTest.php @@ -61,7 +61,9 @@ public function testOpenReturnsPromiseWhichRejectsWithExceptionWhenPathIsInvalid echo 'Error: ' . $e->getMessage() . PHP_EOL; }); - $this->expectOutputString('Error: Unable to open database: unable to open database file' . PHP_EOL); + // Unable to open database: unable to open database file + // Unable to open database: bad parameter or other API misuse (only between PHP 7.4.0 and PHP 7.4.7 as per https://3v4l.org/9SjgK) + $this->expectOutputRegex('/^' . preg_quote('Error: Unable to open database: ', '/') . '.*$/'); Loop::run(); } From 1c3d3f28255c4fba3e7834f7b2528f3572e82dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sun, 7 Nov 2021 15:40:09 +0100 Subject: [PATCH 2/2] Fail fast without waiting for timeout if process dies while connecting --- src/Factory.php | 10 ++++++++++ tests/FunctionalFactoryTest.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Factory.php b/src/Factory.php index d1e4cf1..fa78c6b 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -305,6 +305,16 @@ private function openSocketIo($filename, $flags = null) $deferred->reject(new \RuntimeException('No connection detected')); }); + $process->on('exit', function () use ($deferred, $server, $timeout) { + $this->loop->cancelTimer($timeout); + if (is_resource($server)) { + $this->loop->removeReadStream($server); + fclose($server); + } + + $deferred->reject(new \RuntimeException('Database process died while setting up connection')); + }); + $this->loop->addReadStream($server, function () use ($server, $timeout, $filename, $flags, $deferred, $process) { // accept once connection on server socket and stop server socket $this->loop->cancelTimer($timeout); diff --git a/tests/FunctionalFactoryTest.php b/tests/FunctionalFactoryTest.php index 4ea86a9..96ca66a 100644 --- a/tests/FunctionalFactoryTest.php +++ b/tests/FunctionalFactoryTest.php @@ -84,7 +84,7 @@ public function testOpenReturnsPromiseWhichRejectsWithExceptionWhenExplicitPhpBi echo 'Error: ' . $e->getMessage() . PHP_EOL; }); - $this->expectOutputString('Error: No connection detected' . PHP_EOL); + $this->expectOutputString('Error: Database process died while setting up connection' . PHP_EOL); Loop::run(); } }