Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test suite to avoid unhandled promise rejections #215

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"react/promise": "^3.0 || ^2.7 || ^1.2.1"
},
"require-dev": {
"phpunit/phpunit": "^9.5 || ^4.8.35",
"phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.35",
"react/async": "^4 || ^3 || ^2",
"react/promise-timer": "^1.9"
},
Expand Down
6 changes: 6 additions & 0 deletions tests/FunctionalResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ public function testResolveShouldNotCauseGarbageReferencesWhenUsingInvalidNamese
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->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection

unset($promise);

$this->assertEquals(0, gc_collect_cycles());
Expand All @@ -205,6 +208,9 @@ public function testResolveCachedShouldNotCauseGarbageReferencesWhenUsingInvalid
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->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection

unset($promise);

$this->assertEquals(0, gc_collect_cycles());
Expand Down
4 changes: 3 additions & 1 deletion tests/Query/CoopExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public function testQueryTwiceWillPassExactQueryToBaseExecutorTwiceWhenFirstQuer

$connector = new CoopExecutor($base);

$connector->query($query);
$promise = $connector->query($query);

$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection

$deferred->reject(new RuntimeException());

Expand Down
8 changes: 6 additions & 2 deletions tests/Query/RetryExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ public function queryShouldNotCauseGarbageReferencesOnTimeoutErrors()
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);
$promise = $retryExecutor->query($query);

$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection

$this->assertEquals(0, gc_collect_cycles());
}
Expand Down Expand Up @@ -322,7 +324,9 @@ public function queryShouldNotCauseGarbageReferencesOnNonTimeoutErrors()
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);
$promise = $retryExecutor->query($query);

$promise->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection

$this->assertEquals(0, gc_collect_cycles());
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Query/SelectiveTransportExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ public function testRejectedPromiseAfterTruncatedResponseShouldNotCreateAnyGarba
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->then(null, $this->expectCallableOnce()); // avoid reporting unhandled rejection

unset($promise);

$this->assertEquals(0, gc_collect_cycles());
Expand Down
11 changes: 4 additions & 7 deletions tests/Query/TcpTransportExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,12 @@ public function testQueryRejectsWhenClientKeepsSendingWhenServerClosesSocketWith
$query = new Query('google' . str_repeat('.com', 100), Message::TYPE_A, Message::CLASS_IN);

// send a bunch of queries and keep reference to last promise
$exception = null;
for ($i = 0; $i < 2000; ++$i) {
$promise = $executor->query($query);
$promise->then(null, function (\Exception $reason) use (&$exception) {
$exception = $reason;
});
}

$client = stream_socket_accept($server);
Expand Down Expand Up @@ -399,11 +403,6 @@ public function testQueryRejectsWhenClientKeepsSendingWhenServerClosesSocketWith
restore_error_handler();
$this->assertNull($error);

$exception = null;
$promise->then(null, function ($reason) use (&$exception) {
$exception = $reason;
});

// expect EPIPE (Broken pipe), except for macOS kernel race condition or legacy HHVM
$this->setExpectedException(
'RuntimeException',
Expand Down Expand Up @@ -472,7 +471,6 @@ public function testQueryKeepsPendingIfServerSendsIncompleteMessageLength()
null,
function ($e) use (&$wait) {
$wait = false;
throw $e;
}
);

Expand Down Expand Up @@ -509,7 +507,6 @@ public function testQueryKeepsPendingIfServerSendsIncompleteMessageBody()
null,
function ($e) use (&$wait) {
$wait = false;
throw $e;
}
);

Expand Down
2 changes: 0 additions & 2 deletions tests/Query/UdpTransportExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ public function testQueryKeepsPendingIfServerSendsInvalidMessage()
null,
function ($e) use (&$wait) {
$wait = false;
throw $e;
}
);

Expand Down Expand Up @@ -307,7 +306,6 @@ public function testQueryKeepsPendingIfServerSendsInvalidId()
null,
function ($e) use (&$wait) {
$wait = false;
throw $e;
}
);

Expand Down