Skip to content

Commit 7016d65

Browse files
authored
Merge pull request #181 from clue-labs/tests
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
2 parents c795e50 + e86f14b commit 7016d65

File tree

8 files changed

+44
-25
lines changed

8 files changed

+44
-25
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ php:
99
- 7.1
1010
- 7.2
1111
- 7.3
12-
- hhvm # ignore errors, see below
12+
# - hhvm # requires legacy phpunit & ignore errors, see below
1313

1414
# lock distro so new future defaults will not break the build
1515
dist: trusty
@@ -18,6 +18,8 @@ matrix:
1818
include:
1919
- php: 5.3
2020
dist: precise
21+
- php: hhvm
22+
install: composer require phpunit/phpunit:^5 --dev --no-interaction
2123
allow_failures:
2224
- php: hhvm
2325

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"php": ">=5.3.0"
88
},
99
"require-dev": {
10-
"phpunit/phpunit": "~4.8.35 || ^5.7 || ^6.4"
10+
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35"
1111
},
1212
"suggest": {
1313
"ext-event": "~1.0 for ExtEventLoop",

phpunit.xml.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
12-
bootstrap="tests/bootstrap.php"
11+
bootstrap="vendor/autoload.php"
1312
>
1413
<testsuites>
1514
<testsuite name="React Test Suite">

tests/AbstractLoopTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,13 @@ function () {
491491

492492
public function testRemoveSignalNotRegisteredIsNoOp()
493493
{
494-
$this->loop->removeSignal(SIGINT, function () { });
494+
$this->loop->removeSignal(2, function () { });
495495
$this->assertTrue(true);
496496
}
497497

498+
/**
499+
* @requires extension pcntl
500+
*/
498501
public function testSignal()
499502
{
500503
if (!function_exists('posix_kill') || !function_exists('posix_getpid')) {
@@ -528,6 +531,9 @@ public function testSignal()
528531
$this->assertTrue($calledShouldNot);
529532
}
530533

534+
/**
535+
* @requires extension pcntl
536+
*/
531537
public function testSignalMultipleUsagesForTheSameListener()
532538
{
533539
$funcCallCount = 0;
@@ -552,6 +558,9 @@ public function testSignalMultipleUsagesForTheSameListener()
552558
$this->assertSame(1, $funcCallCount);
553559
}
554560

561+
/**
562+
* @requires extension pcntl
563+
*/
555564
public function testSignalsKeepTheLoopRunning()
556565
{
557566
$loop = $this->loop;
@@ -565,6 +574,9 @@ public function testSignalsKeepTheLoopRunning()
565574
$this->assertRunSlowerThan(1.5);
566575
}
567576

577+
/**
578+
* @requires extension pcntl
579+
*/
568580
public function testSignalsKeepTheLoopRunningAndRemovingItStopsTheLoop()
569581
{
570582
$loop = $this->loop;

tests/SignalsHandlerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
final class SignalsHandlerTest extends TestCase
88
{
9+
/**
10+
* @requires extension pcntl
11+
*/
912
public function testEmittedEventsAndCallHandling()
1013
{
1114
$callCount = 0;

tests/StreamSelectLoopTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,10 @@ public function signalProvider()
4949
/**
5050
* Test signal interrupt when no stream is attached to the loop
5151
* @dataProvider signalProvider
52+
* @requires extension pcntl
5253
*/
5354
public function testSignalInterruptNoStream($signal)
5455
{
55-
if (!extension_loaded('pcntl')) {
56-
$this->markTestSkipped('"pcntl" extension is required to run this test.');
57-
}
58-
5956
// dispatch signal handler every 10ms for 0.1s
6057
$check = $this->loop->addPeriodicTimer(0.01, function() {
6158
pcntl_signal_dispatch();
@@ -80,13 +77,10 @@ public function testSignalInterruptNoStream($signal)
8077
/**
8178
* Test signal interrupt when a stream is attached to the loop
8279
* @dataProvider signalProvider
80+
* @requires extension pcntl
8381
*/
8482
public function testSignalInterruptWithStream($signal)
8583
{
86-
if (!extension_loaded('pcntl')) {
87-
$this->markTestSkipped('"pcntl" extension is required to run this test.');
88-
}
89-
9084
// dispatch signal handler every 10ms
9185
$this->loop->addPeriodicTimer(0.01, function() {
9286
pcntl_signal_dispatch();

tests/Timer/AbstractTimerTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,28 @@ public function testAddTimerReturnsNonPeriodicTimerInstance()
2222
$this->assertFalse($timer->isPeriodic());
2323
}
2424

25+
/**
26+
* @depends testPlatformHasHighAccuracy
27+
*/
2528
public function testAddTimerWillBeInvokedOnceAndBlocksLoopWhenRunning()
2629
{
30+
// Make no strict assumptions about actual time interval. Common
31+
// environments usually provide millisecond accuracy (or better), but
32+
// Travis and other CI systems are slow.
33+
// We try to compensate for this by skipping accurate tests when the
34+
// current platform is known to be inaccurate. We test this by sleeping
35+
// 3x1ms and then measure the time for each iteration before running the
36+
// actual test.
37+
for ($i = 0; $i < 3; ++$i) {
38+
$start = microtime(true);
39+
usleep(1000);
40+
$time = microtime(true) - $start;
41+
42+
if ($time < 0.001 || $time > 0.002) {
43+
$this->markTestSkipped('Platform provides insufficient accuracy (' . $time . ' s)');
44+
}
45+
}
46+
2747
$loop = $this->createLoop();
2848

2949
$loop->addTimer(0.001, $this->expectCallableOnce());
@@ -32,10 +52,8 @@ public function testAddTimerWillBeInvokedOnceAndBlocksLoopWhenRunning()
3252
$loop->run();
3353
$end = microtime(true);
3454

35-
// make no strict assumptions about actual time interval.
36-
// must be at least 0.001s (1ms) and should not take longer than 0.1s
3755
$this->assertGreaterThanOrEqual(0.001, $end - $start);
38-
$this->assertLessThan(0.1, $end - $start);
56+
$this->assertLessThan(0.002, $end - $start);
3957
}
4058

4159
public function testAddPeriodicTimerReturnsPeriodicTimerInstance()

tests/bootstrap.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)