Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward compatibility with PHPUnit 7 and fix false negative test results, use legacy PHPUnit 5 on legacy HHVM, skip signal tests when PCNTL is not available and skip timer tests on inacurrate platforms #181

Merged
merged 2 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="React Test Suite">
Expand Down
14 changes: 13 additions & 1 deletion tests/AbstractLoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -528,6 +531,9 @@ public function testSignal()
$this->assertTrue($calledShouldNot);
}

/**
* @requires extension pcntl
*/
public function testSignalMultipleUsagesForTheSameListener()
{
$funcCallCount = 0;
Expand All @@ -552,6 +558,9 @@ public function testSignalMultipleUsagesForTheSameListener()
$this->assertSame(1, $funcCallCount);
}

/**
* @requires extension pcntl
*/
public function testSignalsKeepTheLoopRunning()
{
$loop = $this->loop;
Expand All @@ -565,6 +574,9 @@ public function testSignalsKeepTheLoopRunning()
$this->assertRunSlowerThan(1.5);
}

/**
* @requires extension pcntl
*/
public function testSignalsKeepTheLoopRunningAndRemovingItStopsTheLoop()
{
$loop = $this->loop;
Expand Down
3 changes: 3 additions & 0 deletions tests/SignalsHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

final class SignalsHandlerTest extends TestCase
{
/**
* @requires extension pcntl
*/
public function testEmittedEventsAndCallHandling()
{
$callCount = 0;
Expand Down
10 changes: 2 additions & 8 deletions tests/StreamSelectLoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
24 changes: 21 additions & 3 deletions tests/Timer/AbstractTimerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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()
Expand Down
9 changes: 0 additions & 9 deletions tests/bootstrap.php

This file was deleted.