aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/php/vendor/react/event-loop/tests/Timer
diff options
context:
space:
mode:
authormarvin-borner@live.com2018-04-10 21:50:16 +0200
committermarvin-borner@live.com2018-04-10 21:54:48 +0200
commitfc9401f04a3aca5abb22f87ebc210de8afe11d32 (patch)
treeb0b310f3581764ec3955f4e496a05137a32951c3 /assets/php/vendor/react/event-loop/tests/Timer
parent286d643180672f20526f3dc3bd19d7b751e2fa97 (diff)
Initial Commit
Diffstat (limited to 'assets/php/vendor/react/event-loop/tests/Timer')
-rw-r--r--assets/php/vendor/react/event-loop/tests/Timer/AbstractTimerTest.php122
-rw-r--r--assets/php/vendor/react/event-loop/tests/Timer/ExtEvTimerTest.php17
-rw-r--r--assets/php/vendor/react/event-loop/tests/Timer/ExtEventTimerTest.php17
-rw-r--r--assets/php/vendor/react/event-loop/tests/Timer/ExtLibevTimerTest.php17
-rw-r--r--assets/php/vendor/react/event-loop/tests/Timer/ExtLibeventTimerTest.php17
-rw-r--r--assets/php/vendor/react/event-loop/tests/Timer/StreamSelectTimerTest.php13
-rw-r--r--assets/php/vendor/react/event-loop/tests/Timer/TimersTest.php27
7 files changed, 230 insertions, 0 deletions
diff --git a/assets/php/vendor/react/event-loop/tests/Timer/AbstractTimerTest.php b/assets/php/vendor/react/event-loop/tests/Timer/AbstractTimerTest.php
new file mode 100644
index 0000000..294e683
--- /dev/null
+++ b/assets/php/vendor/react/event-loop/tests/Timer/AbstractTimerTest.php
@@ -0,0 +1,122 @@
+<?php
+
+namespace React\Tests\EventLoop\Timer;
+
+use React\EventLoop\LoopInterface;
+use React\Tests\EventLoop\TestCase;
+
+abstract class AbstractTimerTest extends TestCase
+{
+ /**
+ * @return LoopInterface
+ */
+ abstract public function createLoop();
+
+ public function testAddTimerReturnsNonPeriodicTimerInstance()
+ {
+ $loop = $this->createLoop();
+
+ $timer = $loop->addTimer(0.001, $this->expectCallableNever());
+
+ $this->assertInstanceOf('React\EventLoop\TimerInterface', $timer);
+ $this->assertFalse($timer->isPeriodic());
+ }
+
+ public function testAddTimerWillBeInvokedOnceAndBlocksLoopWhenRunning()
+ {
+ $loop = $this->createLoop();
+
+ $loop->addTimer(0.001, $this->expectCallableOnce());
+
+ $start = microtime(true);
+ $loop->run();
+ $end = microtime(true);
+
+ // make no strict assumptions about actual time interval.
+ // must be at least 0.001s (1ms) and should not take longer than 0.1s
+ $this->assertGreaterThanOrEqual(0.001, $end - $start);
+ $this->assertLessThan(0.1, $end - $start);
+ }
+
+ public function testAddPeriodicTimerReturnsPeriodicTimerInstance()
+ {
+ $loop = $this->createLoop();
+
+ $periodic = $loop->addPeriodicTimer(0.1, $this->expectCallableNever());
+
+ $this->assertInstanceOf('React\EventLoop\TimerInterface', $periodic);
+ $this->assertTrue($periodic->isPeriodic());
+ }
+
+ public function testAddPeriodicTimerWillBeInvokedUntilItIsCancelled()
+ {
+ $loop = $this->createLoop();
+
+ $periodic = $loop->addPeriodicTimer(0.1, $this->expectCallableExactly(3));
+
+ // make no strict assumptions about actual time interval.
+ // leave some room to ensure this ticks exactly 3 times.
+ $loop->addTimer(0.399, function () use ($loop, $periodic) {
+ $loop->cancelTimer($periodic);
+ });
+
+ $loop->run();
+ }
+
+ public function testAddPeriodicTimerWillBeInvokedWithMaximumAccuracyUntilItIsCancelled()
+ {
+ $loop = $this->createLoop();
+
+ $i = 0;
+ $periodic = $loop->addPeriodicTimer(0.001, function () use (&$i) {
+ ++$i;
+ });
+
+ $loop->addTimer(0.02, function () use ($loop, $periodic) {
+ $loop->cancelTimer($periodic);
+ });
+
+ $loop->run();
+
+ // make no strict assumptions about number of invocations.
+ // we know it must be no more than 20 times and should at least be
+ // invoked twice for really slow loops
+ $this->assertLessThanOrEqual(20, $i);
+ $this->assertGreaterThan(2, $i);
+ }
+
+ public function testAddPeriodicTimerCancelsItself()
+ {
+ $loop = $this->createLoop();
+
+ $i = 0;
+ $loop->addPeriodicTimer(0.001, function ($timer) use (&$i, $loop) {
+ $i++;
+
+ if ($i === 5) {
+ $loop->cancelTimer($timer);
+ }
+ });
+
+ $start = microtime(true);
+ $loop->run();
+ $end = microtime(true);
+
+ $this->assertEquals(5, $i);
+
+ // make no strict assumptions about time interval.
+ // 5 invocations must take at least 0.005s (5ms) and should not take
+ // longer than 0.1s for slower loops.
+ $this->assertGreaterThanOrEqual(0.005, $end - $start);
+ $this->assertLessThan(0.1, $end - $start);
+ }
+
+ public function testMinimumIntervalOneMicrosecond()
+ {
+ $loop = $this->createLoop();
+
+ $timer = $loop->addTimer(0, function () {});
+
+ $this->assertEquals(0.000001, $timer->getInterval());
+ }
+}
diff --git a/assets/php/vendor/react/event-loop/tests/Timer/ExtEvTimerTest.php b/assets/php/vendor/react/event-loop/tests/Timer/ExtEvTimerTest.php
new file mode 100644
index 0000000..bfa9186
--- /dev/null
+++ b/assets/php/vendor/react/event-loop/tests/Timer/ExtEvTimerTest.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace React\Tests\EventLoop\Timer;
+
+use React\EventLoop\ExtEvLoop;
+
+class ExtEvTimerTest extends AbstractTimerTest
+{
+ public function createLoop()
+ {
+ if (!class_exists('EvLoop')) {
+ $this->markTestSkipped('ExtEvLoop tests skipped because ext-ev extension is not installed.');
+ }
+
+ return new ExtEvLoop();
+ }
+}
diff --git a/assets/php/vendor/react/event-loop/tests/Timer/ExtEventTimerTest.php b/assets/php/vendor/react/event-loop/tests/Timer/ExtEventTimerTest.php
new file mode 100644
index 0000000..a7a6d00
--- /dev/null
+++ b/assets/php/vendor/react/event-loop/tests/Timer/ExtEventTimerTest.php
@@ -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();
+ }
+}
diff --git a/assets/php/vendor/react/event-loop/tests/Timer/ExtLibevTimerTest.php b/assets/php/vendor/react/event-loop/tests/Timer/ExtLibevTimerTest.php
new file mode 100644
index 0000000..65e82be
--- /dev/null
+++ b/assets/php/vendor/react/event-loop/tests/Timer/ExtLibevTimerTest.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace React\Tests\EventLoop\Timer;
+
+use React\EventLoop\ExtLibevLoop;
+
+class ExtLibevTimerTest extends AbstractTimerTest
+{
+ public function createLoop()
+ {
+ if (!class_exists('libev\EventLoop')) {
+ $this->markTestSkipped('libev tests skipped because ext-libev is not installed.');
+ }
+
+ return new ExtLibevLoop();
+ }
+}
diff --git a/assets/php/vendor/react/event-loop/tests/Timer/ExtLibeventTimerTest.php b/assets/php/vendor/react/event-loop/tests/Timer/ExtLibeventTimerTest.php
new file mode 100644
index 0000000..9089b9a
--- /dev/null
+++ b/assets/php/vendor/react/event-loop/tests/Timer/ExtLibeventTimerTest.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace React\Tests\EventLoop\Timer;
+
+use React\EventLoop\ExtLibeventLoop;
+
+class ExtLibeventTimerTest extends AbstractTimerTest
+{
+ public function createLoop()
+ {
+ if (!function_exists('event_base_new')) {
+ $this->markTestSkipped('libevent tests skipped because ext-libevent is not installed.');
+ }
+
+ return new ExtLibeventLoop();
+ }
+}
diff --git a/assets/php/vendor/react/event-loop/tests/Timer/StreamSelectTimerTest.php b/assets/php/vendor/react/event-loop/tests/Timer/StreamSelectTimerTest.php
new file mode 100644
index 0000000..cfe1d7d
--- /dev/null
+++ b/assets/php/vendor/react/event-loop/tests/Timer/StreamSelectTimerTest.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace React\Tests\EventLoop\Timer;
+
+use React\EventLoop\StreamSelectLoop;
+
+class StreamSelectTimerTest extends AbstractTimerTest
+{
+ public function createLoop()
+ {
+ return new StreamSelectLoop();
+ }
+}
diff --git a/assets/php/vendor/react/event-loop/tests/Timer/TimersTest.php b/assets/php/vendor/react/event-loop/tests/Timer/TimersTest.php
new file mode 100644
index 0000000..b279478
--- /dev/null
+++ b/assets/php/vendor/react/event-loop/tests/Timer/TimersTest.php
@@ -0,0 +1,27 @@
+<?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()
+ {
+ $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(0.5, function () {
+ $this->fail("Timer shouldn't be called");
+ }));
+
+ $timers->tick();
+
+ $this->assertTrue(true);
+ }
+}