From 9e0b172dd5c9c4cf6f66275b330feee3a7906273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 10 Jul 2020 17:56:22 +0200 Subject: [PATCH 1/2] Fix failing test on PHP 7.4 with code coverage when skipping some tests This only reports an error on PHP 7.4 when executed like this: $ vendor/bin/phpunit --coverage-text --exclude-group internet --- tests/FunctionalResolverTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/FunctionalResolverTest.php b/tests/FunctionalResolverTest.php index 92ccc20e..129c9c0c 100644 --- a/tests/FunctionalResolverTest.php +++ b/tests/FunctionalResolverTest.php @@ -188,6 +188,7 @@ public function testCancelResolveShouldNotCauseGarbageReferences() $this->resolver = $factory->create('127.0.0.1', $this->loop); gc_collect_cycles(); + gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on $promise = $this->resolver->resolve('google.com'); $promise->cancel(); From af398a8b7dc55e3e0b360c81871d8c9d67759a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 10 Jul 2020 18:05:16 +0200 Subject: [PATCH 2/2] Always clear garbage twice to work around sporadic test fails on PHP 7.4 --- tests/FunctionalResolverTest.php | 4 +++- tests/Query/CoopExecutorTest.php | 1 + tests/Query/RetryExecutorTest.php | 6 ++++++ tests/Query/SelectiveTransportExecutorTest.php | 6 ++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/FunctionalResolverTest.php b/tests/FunctionalResolverTest.php index 129c9c0c..d56e677e 100644 --- a/tests/FunctionalResolverTest.php +++ b/tests/FunctionalResolverTest.php @@ -7,7 +7,7 @@ use React\Dns\RecordNotFoundException; use React\Dns\Model\Message; -class FunctionalTest extends TestCase +class FunctionalResolverTest extends TestCase { /** * @before @@ -171,6 +171,7 @@ public function testResolveCachedShouldNotCauseGarbageReferencesWhenUsingInvalid $this->resolver = $factory->createCached('255.255.255.255', $this->loop); gc_collect_cycles(); + gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on $promise = $this->resolver->resolve('google.com'); unset($promise); @@ -207,6 +208,7 @@ public function testCancelResolveCachedShouldNotCauseGarbageReferences() $this->resolver = $factory->createCached('127.0.0.1', $this->loop); gc_collect_cycles(); + gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on $promise = $this->resolver->resolve('google.com'); $promise->cancel(); diff --git a/tests/Query/CoopExecutorTest.php b/tests/Query/CoopExecutorTest.php index 3e5074ec..423f5c59 100644 --- a/tests/Query/CoopExecutorTest.php +++ b/tests/Query/CoopExecutorTest.php @@ -221,6 +221,7 @@ public function testCancelQueryShouldNotCauseGarbageReferences() $connector = new CoopExecutor($base); gc_collect_cycles(); + gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on $query = new Query('reactphp.org', Message::TYPE_A, Message::CLASS_IN); diff --git a/tests/Query/RetryExecutorTest.php b/tests/Query/RetryExecutorTest.php index fe7c51f0..71792160 100644 --- a/tests/Query/RetryExecutorTest.php +++ b/tests/Query/RetryExecutorTest.php @@ -251,6 +251,8 @@ public function queryShouldNotCauseGarbageReferencesOnTimeoutErrors() $retryExecutor = new RetryExecutor($executor, 0); gc_collect_cycles(); + gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on + $query = new Query('igor.io', Message::TYPE_A, Message::CLASS_IN); $retryExecutor->query($query); @@ -281,6 +283,8 @@ public function queryShouldNotCauseGarbageReferencesOnCancellation() $retryExecutor = new RetryExecutor($executor, 0); gc_collect_cycles(); + gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on + $query = new Query('igor.io', Message::TYPE_A, Message::CLASS_IN); $promise = $retryExecutor->query($query); $promise->cancel(); @@ -311,6 +315,8 @@ public function queryShouldNotCauseGarbageReferencesOnNonTimeoutErrors() $retryExecutor = new RetryExecutor($executor, 2); gc_collect_cycles(); + gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on + $query = new Query('igor.io', Message::TYPE_A, Message::CLASS_IN); $retryExecutor->query($query); diff --git a/tests/Query/SelectiveTransportExecutorTest.php b/tests/Query/SelectiveTransportExecutorTest.php index a2632045..a6cf29e0 100644 --- a/tests/Query/SelectiveTransportExecutorTest.php +++ b/tests/Query/SelectiveTransportExecutorTest.php @@ -159,6 +159,8 @@ public function testCancelPromiseShouldNotCreateAnyGarbageReferences() })); gc_collect_cycles(); + gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on + $promise = $this->executor->query($query); $promise->cancel(); unset($promise); @@ -190,6 +192,8 @@ public function testCancelPromiseAfterTruncatedResponseShouldNotCreateAnyGarbage })); gc_collect_cycles(); + gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on + $promise = $this->executor->query($query); $deferred->reject(new \RuntimeException('', defined('SOCKET_EMSGSIZE') ? SOCKET_EMSGSIZE : 90)); $promise->cancel(); @@ -215,6 +219,8 @@ public function testRejectedPromiseAfterTruncatedResponseShouldNotCreateAnyGarba ->willReturn(\React\Promise\reject(new \RuntimeException())); gc_collect_cycles(); + gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on + $promise = $this->executor->query($query); unset($promise);