Skip to content

Commit 7935564

Browse files
committed
Add a test ensuring that watchers are enabled in the actual next tick
1 parent 33d9995 commit 7935564

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/Test.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,31 @@ function testLoopStopPreventsTimerExecution()
12141214
$this->assertTrue($t + 0.1 > microtime(1));
12151215
}
12161216

1217+
function testDeferEnabledInNextTick() {
1218+
$tick = function() {
1219+
$this->loop->defer(function() {
1220+
$this->loop->stop();
1221+
});
1222+
$this->loop->run();
1223+
};
1224+
1225+
$invoked = 0;
1226+
1227+
$repeat = $this->loop->repeat($delay = 0, function () use (&$invoked) {
1228+
$invoked++;
1229+
});
1230+
1231+
$tick();
1232+
$tick();
1233+
$tick();
1234+
1235+
$this->loop->disable($repeat);
1236+
$this->loop->enable($repeat);
1237+
$tick(); // disable + immediate enable after a tick should have no effect either
1238+
1239+
$this->assertEquals(4, $invoked);
1240+
}
1241+
12171242
// getState and setState are final, but test it here again to be sure
12181243
function testRegistry() {
12191244
$this->assertNull($this->loop->getState("foo"));

0 commit comments

Comments
 (0)