From 858b18a37f72af171268ecec3f5ffdf81400748d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 21 Dec 2019 15:20:52 +0100 Subject: [PATCH 1/2] Fix failing test cases due to inaccurate timers --- tests/Timer/AbstractTimerTest.php | 47 ++++++++++--------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/tests/Timer/AbstractTimerTest.php b/tests/Timer/AbstractTimerTest.php index 0f96c9fe..cd53bd13 100644 --- a/tests/Timer/AbstractTimerTest.php +++ b/tests/Timer/AbstractTimerTest.php @@ -22,38 +22,21 @@ public function testAddTimerReturnsNonPeriodicTimerInstance() $this->assertFalse($timer->isPeriodic()); } - /** - * @depends testPlatformHasHighAccuracy - */ public function testAddTimerWillBeInvokedOnceAndBlocksLoopWhenRunning() { - // Make no strict assumptions about actual time interval. Common - // environments usually provide millisecond accuracy (or better), but - // Travis and other CI systems are slow. - // We try to compensate for this by skipping accurate tests when the - // current platform is known to be inaccurate. We test this by sleeping - // 3x1ms and then measure the time for each iteration before running the - // actual test. - for ($i = 0; $i < 3; ++$i) { - $start = microtime(true); - usleep(1000); - $time = microtime(true) - $start; - - if ($time < 0.001 || $time > 0.002) { - $this->markTestSkipped('Platform provides insufficient accuracy (' . $time . ' s)'); - } - } - $loop = $this->createLoop(); - $loop->addTimer(0.001, $this->expectCallableOnce()); + $loop->addTimer(0.002, $this->expectCallableOnce()); $start = microtime(true); $loop->run(); $end = microtime(true); + // 1 invocation should take 2ms (± 1ms due to timer inaccuracies) + // make no strict assumptions about time interval, must at least take 1ms + // and should not take longer than 0.1s for slower loops. $this->assertGreaterThanOrEqual(0.001, $end - $start); - $this->assertLessThan(0.002, $end - $start); + $this->assertLessThan(0.1, $end - $start); } public function testAddPeriodicTimerReturnsPeriodicTimerInstance() @@ -90,17 +73,17 @@ public function testAddPeriodicTimerWillBeInvokedWithMaximumAccuracyUntilItIsCan ++$i; }); - $loop->addTimer(0.02, function () use ($loop, $periodic) { + $loop->addTimer(0.1, 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); + // we know it must be no more than 100 times and should at least be + // invoked 4 times for really slow loops + $this->assertLessThanOrEqual(100, $i); + $this->assertGreaterThanOrEqual(4, $i); } public function testAddPeriodicTimerCancelsItself() @@ -122,11 +105,11 @@ public function testAddPeriodicTimerCancelsItself() $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); + // 5 invocations should take 5ms (± 1ms due to timer inaccuracies) + // make no strict assumptions about time interval, must at least take 4ms + // and should not take longer than 0.2s for slower loops. + $this->assertGreaterThanOrEqual(0.004, $end - $start); + $this->assertLessThan(0.2, $end - $start); } public function testMinimumIntervalOneMicrosecond() From 131d92dcf7397ee4b93b268f7248c1ce20df99b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 23 Dec 2019 20:12:06 +0100 Subject: [PATCH 2/2] Run tests on Windows via Travis CI --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index be9cf010..3329ead7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,8 +28,18 @@ matrix: - php: hhvm install: composer require phpunit/phpunit:^5 --dev --no-interaction before_install: [] # skip libuv + - name: "Windows" + os: windows + language: shell # no built-in php support + before_install: + - choco install php + - choco install composer + - export PATH="$(powershell -Command '("Process", "Machine" | % { [Environment]::GetEnvironmentVariable("PATH", $_) -Split ";" -Replace "\\$", "" } | Select -Unique | % { cygpath $_ }) -Join ":"')" + install: + - composer install allow_failures: - php: hhvm + - os: windows sudo: false pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy