Skip to content

Commit

Permalink
Merge pull request #66 from clue-labs/unhandled-rejections
Browse files Browse the repository at this point in the history
Update test suite to avoid unhandled promise rejections
  • Loading branch information
WyriHaximus committed Jul 7, 2023
2 parents 3dbc371 + 784c55a commit a406555
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tests/FunctionRejectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public function testWaitingForPromiseToRejectDoesNotLeaveGarbageCycles()
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on

$promise = Timer\reject(0.01);

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

Loop::run();

unset($promise);

$this->assertEquals(0, gc_collect_cycles());
Expand Down
16 changes: 14 additions & 2 deletions tests/FunctionTimeoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public function testRejectedWillNotStartTimer()
{
$promise = Promise\reject(new \Exception('reject'));

Timer\timeout($promise, 3);
$promise = Timer\timeout($promise, 3);

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

$time = microtime(true);
Loop::run();
Expand Down Expand Up @@ -83,7 +85,9 @@ public function testPendingCancellableWillBeCancelledThroughFollowerOnTimeout()
$promise = $this->getMockBuilder($cancellableInterface)->getMock();
$promise->expects($this->once())->method('then')->willReturn($cancellable);

Timer\timeout($promise, 0.01);
$promise = Timer\timeout($promise, 0.01);

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

Loop::run();
}
Expand Down Expand Up @@ -210,6 +214,8 @@ public function testWaitingForPromiseToRejectBeforeTimeoutDoesNotLeaveGarbageCyc

$promise = Timer\timeout($promise, 1.0);

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

Loop::run();
unset($promise);

Expand All @@ -230,6 +236,8 @@ public function testWaitingForPromiseToTimeoutDoesNotLeaveGarbageCycles()

$promise = Timer\timeout($promise, 0.01);

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

Loop::run();
unset($promise);

Expand All @@ -248,6 +256,8 @@ public function testWaitingForPromiseToTimeoutWithoutCancellerDoesNotLeaveGarbag

$promise = Timer\timeout($promise, 0.01);

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

Loop::run();
unset($promise);

Expand All @@ -268,6 +278,8 @@ public function testWaitingForPromiseToTimeoutWithNoOpCancellerDoesNotLeaveGarba

$promise = Timer\timeout($promise, 0.01);

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

Loop::run();
unset($promise);

Expand Down

0 comments on commit a406555

Please sign in to comment.