mirror of
https://github.com/danog/amp.git
synced 2024-11-30 04:29:08 +01:00
c12828081f
This has been an edge case potentially hiding some exceptions. The tests have been refactored to error if the loop has watchers leaking from one test to another test.
40 lines
1.0 KiB
PHP
40 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace Amp\Test;
|
|
|
|
use Amp\CancelledException;
|
|
use Amp\Delayed;
|
|
use Amp\Loop;
|
|
use Amp\TimeoutCancellationToken;
|
|
use Amp\TimeoutException;
|
|
|
|
class TimeoutCancellationTokenTest extends BaseTest
|
|
{
|
|
public function testTimeout()
|
|
{
|
|
Loop::run(function () {
|
|
$token = new TimeoutCancellationToken(10);
|
|
|
|
$this->assertFalse($token->isRequested());
|
|
yield new Delayed(20);
|
|
$this->assertTrue($token->isRequested());
|
|
|
|
try {
|
|
$token->throwIfRequested();
|
|
} catch (CancelledException $exception) {
|
|
$this->assertInstanceOf(TimeoutException::class, $exception->getPrevious());
|
|
}
|
|
});
|
|
}
|
|
|
|
public function testWatcherCancellation()
|
|
{
|
|
Loop::run(function () {
|
|
$token = new TimeoutCancellationToken(1);
|
|
$this->assertSame(1, Loop::getInfo()["delay"]["enabled"]);
|
|
unset($token);
|
|
$this->assertSame(0, Loop::getInfo()["delay"]["enabled"]);
|
|
});
|
|
}
|
|
}
|