From dbdf5275b2d0bbe1fcecec1aaefb968e107eb4b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 3 Dec 2018 12:57:02 +0100 Subject: [PATCH 1/2] Skip signal tests w/o PCNTL and skip timer tests on inaccurate platforms The signal constants are only available when ext-pcntl is loaded. If it is not loaded, simply skip all tests that reference these constants. Before running a timer test and asserting its time interval, run a simple test to check the accuracy on the current platform. This is known to work on most common platforms, but will now avoid false negative test results on platforms that are known to be slow (Travis CI and others). --- phpunit.xml.dist | 2 +- tests/AbstractLoopTest.php | 14 +++++++++++++- tests/SignalsHandlerTest.php | 3 +++ tests/StreamSelectLoopTest.php | 10 ++-------- tests/Timer/AbstractTimerTest.php | 24 +++++++++++++++++++++--- tests/bootstrap.php | 9 --------- 6 files changed, 40 insertions(+), 22 deletions(-) delete mode 100644 tests/bootstrap.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cba6d4dd..13d3fab0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,7 @@ processIsolation="false" stopOnFailure="false" syntaxCheck="false" - bootstrap="tests/bootstrap.php" + bootstrap="vendor/autoload.php" > diff --git a/tests/AbstractLoopTest.php b/tests/AbstractLoopTest.php index 3d844382..83f5756b 100644 --- a/tests/AbstractLoopTest.php +++ b/tests/AbstractLoopTest.php @@ -491,10 +491,13 @@ function () { public function testRemoveSignalNotRegisteredIsNoOp() { - $this->loop->removeSignal(SIGINT, function () { }); + $this->loop->removeSignal(2, function () { }); $this->assertTrue(true); } + /** + * @requires extension pcntl + */ public function testSignal() { if (!function_exists('posix_kill') || !function_exists('posix_getpid')) { @@ -528,6 +531,9 @@ public function testSignal() $this->assertTrue($calledShouldNot); } + /** + * @requires extension pcntl + */ public function testSignalMultipleUsagesForTheSameListener() { $funcCallCount = 0; @@ -552,6 +558,9 @@ public function testSignalMultipleUsagesForTheSameListener() $this->assertSame(1, $funcCallCount); } + /** + * @requires extension pcntl + */ public function testSignalsKeepTheLoopRunning() { $loop = $this->loop; @@ -565,6 +574,9 @@ public function testSignalsKeepTheLoopRunning() $this->assertRunSlowerThan(1.5); } + /** + * @requires extension pcntl + */ public function testSignalsKeepTheLoopRunningAndRemovingItStopsTheLoop() { $loop = $this->loop; diff --git a/tests/SignalsHandlerTest.php b/tests/SignalsHandlerTest.php index f8b7df3d..a8cc4221 100644 --- a/tests/SignalsHandlerTest.php +++ b/tests/SignalsHandlerTest.php @@ -6,6 +6,9 @@ final class SignalsHandlerTest extends TestCase { + /** + * @requires extension pcntl + */ public function testEmittedEventsAndCallHandling() { $callCount = 0; diff --git a/tests/StreamSelectLoopTest.php b/tests/StreamSelectLoopTest.php index bd19e1cd..2eb388f0 100644 --- a/tests/StreamSelectLoopTest.php +++ b/tests/StreamSelectLoopTest.php @@ -49,13 +49,10 @@ public function signalProvider() /** * Test signal interrupt when no stream is attached to the loop * @dataProvider signalProvider + * @requires extension pcntl */ public function testSignalInterruptNoStream($signal) { - if (!extension_loaded('pcntl')) { - $this->markTestSkipped('"pcntl" extension is required to run this test.'); - } - // dispatch signal handler every 10ms for 0.1s $check = $this->loop->addPeriodicTimer(0.01, function() { pcntl_signal_dispatch(); @@ -80,13 +77,10 @@ public function testSignalInterruptNoStream($signal) /** * Test signal interrupt when a stream is attached to the loop * @dataProvider signalProvider + * @requires extension pcntl */ public function testSignalInterruptWithStream($signal) { - if (!extension_loaded('pcntl')) { - $this->markTestSkipped('"pcntl" extension is required to run this test.'); - } - // dispatch signal handler every 10ms $this->loop->addPeriodicTimer(0.01, function() { pcntl_signal_dispatch(); diff --git a/tests/Timer/AbstractTimerTest.php b/tests/Timer/AbstractTimerTest.php index 294e683f..11187b31 100644 --- a/tests/Timer/AbstractTimerTest.php +++ b/tests/Timer/AbstractTimerTest.php @@ -22,8 +22,28 @@ 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()); @@ -32,10 +52,8 @@ public function testAddTimerWillBeInvokedOnceAndBlocksLoopWhenRunning() $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); + $this->assertLessThan(0.002, $end - $start); } public function testAddPeriodicTimerReturnsPeriodicTimerInstance() diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index aeb44352..00000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,9 +0,0 @@ - Date: Mon, 4 Feb 2019 12:02:08 +0100 Subject: [PATCH 2/2] Forward compatibility with PHPUnit 7 and use legacy PHPUnit 5 on HHVM --- .travis.yml | 4 +++- composer.json | 2 +- phpunit.xml.dist | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4e946173..fe9bd21c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ php: - 7.1 - 7.2 - 7.3 - - hhvm # ignore errors, see below +# - hhvm # requires legacy phpunit & ignore errors, see below # lock distro so new future defaults will not break the build dist: trusty @@ -18,6 +18,8 @@ matrix: include: - php: 5.3 dist: precise + - php: hhvm + install: composer require phpunit/phpunit:^5 --dev --no-interaction allow_failures: - php: hhvm diff --git a/composer.json b/composer.json index f6517df4..cc6abf06 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "php": ">=5.3.0" }, "require-dev": { - "phpunit/phpunit": "~4.8.35 || ^5.7 || ^6.4" + "phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35" }, "suggest": { "ext-event": "~1.0 for ExtEventLoop", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 13d3fab0..04d426b5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="vendor/autoload.php" > 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