1
0
mirror of https://github.com/danog/amp.git synced 2024-11-30 04:29:08 +01:00

Add tests to ensure unreferenced watchers are still executed and negative expiration doesn't create issues

This commit is contained in:
Niklas Keller 2017-01-08 17:56:59 +01:00
parent 0b899f5bcd
commit 5aeff2c7d2

View File

@ -176,6 +176,34 @@ abstract class Test extends \PHPUnit_Framework_TestCase {
});
}
function testUnreferencedDeferWatcherStillExecutes()
{
$invoked = false;
$this->start(function(Driver $loop) use (&$invoked) {
$watcher = $loop->defer(function () use (&$invoked) {
$invoked = true;
});
$loop->unreference($watcher);
$loop->defer(function () {
// just to keep loop running
});
});
$this->assertTrue($invoked);
}
function testLoopDoesNotBlockOnNegativeTimerExpiration()
{
$invoked = false;
$this->start(function(Driver $loop) use (&$invoked) {
$loop->delay(1, function () use (&$invoked) {
$invoked = true;
});
usleep(1000 * 10);
});
$this->assertTrue($invoked);
}
function testDisabledDeferReenableInSubsequentTick()
{
$this->expectOutputString("123");