mirror of
https://github.com/danog/amp.git
synced 2025-01-22 05:11:42 +01:00
Add a test ensuring that watchers are enabled in the actual next tick
This commit is contained in:
parent
33d9995b8c
commit
79355641ed
25
src/Test.php
25
src/Test.php
@ -1214,6 +1214,31 @@ abstract class Test extends \PHPUnit_Framework_TestCase {
|
||||
$this->assertTrue($t + 0.1 > microtime(1));
|
||||
}
|
||||
|
||||
function testDeferEnabledInNextTick() {
|
||||
$tick = function() {
|
||||
$this->loop->defer(function() {
|
||||
$this->loop->stop();
|
||||
});
|
||||
$this->loop->run();
|
||||
};
|
||||
|
||||
$invoked = 0;
|
||||
|
||||
$repeat = $this->loop->repeat($delay = 0, function () use (&$invoked) {
|
||||
$invoked++;
|
||||
});
|
||||
|
||||
$tick();
|
||||
$tick();
|
||||
$tick();
|
||||
|
||||
$this->loop->disable($repeat);
|
||||
$this->loop->enable($repeat);
|
||||
$tick(); // disable + immediate enable after a tick should have no effect either
|
||||
|
||||
$this->assertEquals(4, $invoked);
|
||||
}
|
||||
|
||||
// getState and setState are final, but test it here again to be sure
|
||||
function testRegistry() {
|
||||
$this->assertNull($this->loop->getState("foo"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user