init
This commit is contained in:
97
vendor/react/event-loop/tests/Timer/AbstractTimerTest.php
vendored
Executable file
97
vendor/react/event-loop/tests/Timer/AbstractTimerTest.php
vendored
Executable file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace React\Tests\EventLoop\Timer;
|
||||
|
||||
use React\Tests\EventLoop\TestCase;
|
||||
|
||||
abstract class AbstractTimerTest extends TestCase
|
||||
{
|
||||
abstract public function createLoop();
|
||||
|
||||
public function testAddTimer()
|
||||
{
|
||||
// usleep is intentionally high
|
||||
|
||||
$loop = $this->createLoop();
|
||||
|
||||
$loop->addTimer(0.001, $this->expectCallableOnce());
|
||||
usleep(1000);
|
||||
$loop->tick();
|
||||
}
|
||||
|
||||
public function testAddPeriodicTimer()
|
||||
{
|
||||
$loop = $this->createLoop();
|
||||
|
||||
$loop->addPeriodicTimer(0.001, $this->expectCallableExactly(3));
|
||||
usleep(1000);
|
||||
$loop->tick();
|
||||
usleep(1000);
|
||||
$loop->tick();
|
||||
usleep(1000);
|
||||
$loop->tick();
|
||||
}
|
||||
|
||||
public function testAddPeriodicTimerWithCancel()
|
||||
{
|
||||
$loop = $this->createLoop();
|
||||
|
||||
$timer = $loop->addPeriodicTimer(0.001, $this->expectCallableExactly(2));
|
||||
|
||||
usleep(1000);
|
||||
$loop->tick();
|
||||
usleep(1000);
|
||||
$loop->tick();
|
||||
|
||||
$timer->cancel();
|
||||
|
||||
usleep(1000);
|
||||
$loop->tick();
|
||||
}
|
||||
|
||||
public function testAddPeriodicTimerCancelsItself()
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
$loop = $this->createLoop();
|
||||
|
||||
$loop->addPeriodicTimer(0.001, function ($timer) use (&$i) {
|
||||
$i++;
|
||||
|
||||
if ($i == 2) {
|
||||
$timer->cancel();
|
||||
}
|
||||
});
|
||||
|
||||
usleep(1000);
|
||||
$loop->tick();
|
||||
usleep(1000);
|
||||
$loop->tick();
|
||||
usleep(1000);
|
||||
$loop->tick();
|
||||
|
||||
$this->assertSame(2, $i);
|
||||
}
|
||||
|
||||
public function testIsTimerActive()
|
||||
{
|
||||
$loop = $this->createLoop();
|
||||
|
||||
$timer = $loop->addPeriodicTimer(0.001, function () {});
|
||||
|
||||
$this->assertTrue($loop->isTimerActive($timer));
|
||||
|
||||
$timer->cancel();
|
||||
|
||||
$this->assertFalse($loop->isTimerActive($timer));
|
||||
}
|
||||
|
||||
public function testMinimumIntervalOneMicrosecond()
|
||||
{
|
||||
$loop = $this->createLoop();
|
||||
|
||||
$timer = $loop->addTimer(0, function () {});
|
||||
|
||||
$this->assertEquals(0.000001, $timer->getInterval());
|
||||
}
|
||||
}
|
||||
17
vendor/react/event-loop/tests/Timer/ExtEventTimerTest.php
vendored
Executable file
17
vendor/react/event-loop/tests/Timer/ExtEventTimerTest.php
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace React\Tests\EventLoop\Timer;
|
||||
|
||||
use React\EventLoop\ExtEventLoop;
|
||||
|
||||
class ExtEventTimerTest extends AbstractTimerTest
|
||||
{
|
||||
public function createLoop()
|
||||
{
|
||||
if (!extension_loaded('event')) {
|
||||
$this->markTestSkipped('ext-event tests skipped because ext-event is not installed.');
|
||||
}
|
||||
|
||||
return new ExtEventLoop();
|
||||
}
|
||||
}
|
||||
17
vendor/react/event-loop/tests/Timer/LibEvTimerTest.php
vendored
Executable file
17
vendor/react/event-loop/tests/Timer/LibEvTimerTest.php
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace React\Tests\EventLoop\Timer;
|
||||
|
||||
use React\EventLoop\LibEvLoop;
|
||||
|
||||
class LibEvTimerTest extends AbstractTimerTest
|
||||
{
|
||||
public function createLoop()
|
||||
{
|
||||
if (!class_exists('libev\EventLoop')) {
|
||||
$this->markTestSkipped('libev tests skipped because ext-libev is not installed.');
|
||||
}
|
||||
|
||||
return new LibEvLoop();
|
||||
}
|
||||
}
|
||||
17
vendor/react/event-loop/tests/Timer/LibEventTimerTest.php
vendored
Executable file
17
vendor/react/event-loop/tests/Timer/LibEventTimerTest.php
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace React\Tests\EventLoop\Timer;
|
||||
|
||||
use React\EventLoop\LibEventLoop;
|
||||
|
||||
class LibEventTimerTest extends AbstractTimerTest
|
||||
{
|
||||
public function createLoop()
|
||||
{
|
||||
if (!function_exists('event_base_new')) {
|
||||
$this->markTestSkipped('libevent tests skipped because ext-libevent is not installed.');
|
||||
}
|
||||
|
||||
return new LibEventLoop();
|
||||
}
|
||||
}
|
||||
13
vendor/react/event-loop/tests/Timer/StreamSelectTimerTest.php
vendored
Executable file
13
vendor/react/event-loop/tests/Timer/StreamSelectTimerTest.php
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace React\Tests\EventLoop\Timer;
|
||||
|
||||
use React\EventLoop\StreamSelectLoop;
|
||||
|
||||
class StreamSelectTimerTest extends AbstractTimerTest
|
||||
{
|
||||
public function createLoop()
|
||||
{
|
||||
return new StreamSelectLoop();
|
||||
}
|
||||
}
|
||||
29
vendor/react/event-loop/tests/Timer/TimersTest.php
vendored
Executable file
29
vendor/react/event-loop/tests/Timer/TimersTest.php
vendored
Executable file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace React\Tests\EventLoop\Timer;
|
||||
|
||||
use React\Tests\EventLoop\TestCase;
|
||||
use React\EventLoop\Timer\Timer;
|
||||
use React\EventLoop\Timer\Timers;
|
||||
|
||||
class TimersTest extends TestCase
|
||||
{
|
||||
public function testBlockedTimer()
|
||||
{
|
||||
$loop = $this
|
||||
->getMockBuilder('React\EventLoop\LoopInterface')
|
||||
->getMock();
|
||||
|
||||
$timers = new Timers();
|
||||
$timers->tick();
|
||||
|
||||
// simulate a bunch of processing on stream events,
|
||||
// part of which schedules a future timer...
|
||||
sleep(1);
|
||||
$timers->add(new Timer($loop, 0.5, function () {
|
||||
$this->fail("Timer shouldn't be called");
|
||||
}));
|
||||
|
||||
$timers->tick();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user