diff --git a/.gitattributes b/.gitattributes index ce7c8e68..fc0be872 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,8 +1,7 @@ /.gitattributes export-ignore +/.github/ export-ignore /.gitignore export-ignore -/.travis.yml export-ignore -/examples export-ignore +/examples/ export-ignore /phpunit.xml.dist export-ignore /phpunit.xml.legacy export-ignore -/tests export-ignore -/travis-init.sh export-ignore +/tests/ export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..92f06ab7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,112 @@ +name: CI + +on: + push: + pull_request: + +jobs: + PHPUnit: + name: PHPUnit (PHP ${{ matrix.php }}) + runs-on: ubuntu-18.04 # legacy Ubuntu 18.04 for legacy libevent + strategy: + matrix: + php: + - 8.0 + - 7.4 + - 7.3 + - 7.2 + - 7.1 + - 7.0 + - 5.6 + - 5.5 + - 5.4 + - 5.3 + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: xdebug + - run: sudo apt-get update && sudo apt-get install libevent-dev + - name: Install ext-event between PHP 5.4 and PHP 7.x + run: | + echo "yes" | sudo pecl install event + # explicitly enable extensions in php.ini on PHP 5.6+ + php -r 'exit((int)(PHP_VERSION_ID >= 50600));' || echo "extension=event.so" | sudo tee -a "$(php -r 'echo php_ini_loaded_file();')" + if: ${{ matrix.php >= 5.4 && matrix.php < 8.0 }} + - name: Install ext-ev on PHP >= 5.4 + run: | + echo "yes" | sudo pecl install ev + # explicitly enable extensions in php.ini on PHP 5.6+ + php -r 'exit((int)(PHP_VERSION_ID >= 50600));' || echo "extension=ev.so" | sudo tee -a "$(php -r 'echo php_ini_loaded_file();')" + if: ${{ matrix.php >= 5.4 }} + - name: Install ext-uv on PHP 7.x + run: | + sudo add-apt-repository ppa:ondrej/php -y && sudo apt-get update -q && sudo apt-get install libuv1-dev + echo "yes" | sudo pecl install uv-beta + echo "extension=uv.so" >> "$(php -r 'echo php_ini_loaded_file();')" + if: ${{ matrix.php >= 7.0 && matrix.php < 8.0 }} + - name: Install legacy ext-libevent on PHP < 7.0 + run: | + curl http://pecl.php.net/get/libevent-0.1.0.tgz | tar -xz + pushd libevent-0.1.0 + phpize + ./configure + make + sudo make install + popd + echo "extension=libevent.so" | sudo tee -a "$(php -r 'echo php_ini_loaded_file();')" + if: ${{ matrix.php < 7.0 }} + - name: Install legacy ext-libev on PHP < 7.0 + run: | + git clone --recursive https://github.com/m4rw3r/php-libev + pushd php-libev + phpize + ./configure --with-libev + make + sudo make install + popd + echo "extension=libev.so" | sudo tee -a "$(php -r 'echo php_ini_loaded_file();')" + if: ${{ matrix.php < 7.0 }} + - run: composer install + - run: vendor/bin/phpunit --coverage-text + if: ${{ matrix.php >= 7.3 }} + - run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy + if: ${{ matrix.php < 7.3 }} + + PHPUnit-Windows: + name: PHPUnit (PHP ${{ matrix.php }} on Windows) + runs-on: windows-2019 + continue-on-error: true + strategy: + matrix: + php: + - 8.0 + - 7.4 + - 7.3 + - 7.2 + - 7.1 + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: xdebug + extensions: sockets,event # future: add uv-beta (installs, but can not load) + - run: composer install + - run: vendor/bin/phpunit --coverage-text + if: ${{ matrix.php >= 7.3 }} + - run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy + if: ${{ matrix.php < 7.3 }} + + PHPUnit-hhvm: + name: PHPUnit (HHVM) + runs-on: ubuntu-18.04 + continue-on-error: true + steps: + - uses: actions/checkout@v2 + - uses: azjezz/setup-hhvm@v1 + with: + version: lts-3.30 + - run: hhvm $(which composer) install + - run: hhvm vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index 81b92580..5cf9a2cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -composer.lock -phpunit.xml -vendor +/composer.lock +/phpunit.xml +/vendor/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e3ac120a..00000000 --- a/.travis.yml +++ /dev/null @@ -1,89 +0,0 @@ -language: php - -# lock distro so new future defaults will not break the build -dist: xenial - -jobs: - include: - - php: 5.3 - dist: precise - before_install: [] # skip libuv - - php: 5.4 - dist: trusty - before_install: [] # skip libuv - - php: 5.5 - dist: trusty - before_install: [] # skip libuv - - php: 5.6 - - php: 7.0 - - php: 7.1 - - php: 7.2 - - php: 7.3 - - php: 7.4 - - php: hhvm-3.18 - dist: trusty - before_install: [] # skip libuv - install: - - composer install # skip ./travis-init.sh - - 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 - - name: "Windows PHP 7.2 with ext-event" - os: windows - language: shell # no built-in php support - before_install: - - curl -OL https://windows.php.net/downloads/pecl/releases/event/2.5.3/php_event-2.5.3-7.2-nts-vc15-x64.zip # latest version as of 2019-12-23 - - choco install php --version=7.2.26 # latest version supported by ext-event as of 2019-12-23 - - choco install composer - - export PATH="$(powershell -Command '("Process", "Machine" | % { [Environment]::GetEnvironmentVariable("PATH", $_) -Split ";" -Replace "\\$", "" } | Select -Unique | % { cygpath $_ }) -Join ":"')" - - php -r "\$z=new ZipArchive();\$z->open(glob('php_event*.zip')[0]);\$z->extractTo(dirname(php_ini_loaded_file()).'/ext','php_event.dll');" - - php -r "file_put_contents(php_ini_loaded_file(),'extension_dir=ext'.PHP_EOL,FILE_APPEND);" - - php -r "file_put_contents(php_ini_loaded_file(),'extension=sockets'.PHP_EOL,FILE_APPEND);" # ext-sockets needs to be loaded before ext-event - - php -r "file_put_contents(php_ini_loaded_file(),'extension=event'.PHP_EOL,FILE_APPEND);" - install: - - composer install - - name: "Windows PHP 7.4 with ext-uv" - os: windows - language: shell # no built-in php support - before_install: - - curl -OL https://windows.php.net/downloads/pecl/releases/uv/0.2.4/php_uv-0.2.4-7.4-nts-vc15-x64.zip # latest version as of 2019-12-23 - - choco install php --version=7.4.0 # latest version supported by ext-uv as of 2019-12-23 - - choco install composer - - export PATH="$(powershell -Command '("Process", "Machine" | % { [Environment]::GetEnvironmentVariable("PATH", $_) -Split ";" -Replace "\\$", "" } | Select -Unique | % { cygpath $_ }) -Join ":"')" - - php -r "\$z=new ZipArchive();\$z->open(glob('php_uv*.zip')[0]);\$z->extractTo(dirname(php_ini_loaded_file()).'/ext','php_uv.dll');\$z->extractTo(dirname(php_ini_loaded_file()),'libuv.dll');" - - php -r "file_put_contents(php_ini_loaded_file(),'extension_dir=ext'.PHP_EOL,FILE_APPEND);" - - php -r "file_put_contents(php_ini_loaded_file(),'extension=sockets'.PHP_EOL,FILE_APPEND);" # ext-sockets needs to be loaded before ext-uv - - php -r "file_put_contents(php_ini_loaded_file(),'extension=uv'.PHP_EOL,FILE_APPEND);" - install: - - composer install - allow_failures: - - php: hhvm-3.18 - - os: windows - -addons: - apt: - packages: - - libevent-dev # Used by 'event' and 'libevent' PHP extensions - -cache: - directories: - - $HOME/.composer/cache/files - -before_install: - - sudo add-apt-repository ppa:ondrej/php -y - - sudo apt-get update -q - - sudo apt-get install libuv1-dev - -install: - - ./travis-init.sh - - composer install - -script: - - if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi - - if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy; fi diff --git a/README.md b/README.md index 402309b1..853766b2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # EventLoop Component -[![Build Status](https://travis-ci.org/reactphp/event-loop.svg?branch=master)](https://travis-ci.org/reactphp/event-loop) +[![CI status](https://github.com/reactphp/event-loop/workflows/CI/badge.svg)](https://github.com/reactphp/event-loop/actions) [ReactPHP](https://reactphp.org/)'s core reactor event loop that libraries can use for evented I/O. @@ -702,7 +702,7 @@ $ composer require react/event-loop:^1.1.1 See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades. This project aims to run on any platform and thus does not require any PHP -extensions and supports running on legacy PHP 5.3 through current PHP 7+ and +extensions and supports running on legacy PHP 5.3 through current PHP 8+ and HHVM. It's *highly recommended to use PHP 7+* for this project. diff --git a/tests/AbstractLoopTest.php b/tests/AbstractLoopTest.php index 292ffd1a..61790882 100644 --- a/tests/AbstractLoopTest.php +++ b/tests/AbstractLoopTest.php @@ -727,7 +727,7 @@ public function testSignalsKeepTheLoopRunning() $loop->stop(); }); - $this->assertRunSlowerThan(1.5); + $this->assertRunSlowerThan(1.4); } /** diff --git a/tests/Timer/AbstractTimerTest.php b/tests/Timer/AbstractTimerTest.php index cd53bd13..c5198385 100644 --- a/tests/Timer/AbstractTimerTest.php +++ b/tests/Timer/AbstractTimerTest.php @@ -26,13 +26,13 @@ public function testAddTimerWillBeInvokedOnceAndBlocksLoopWhenRunning() { $loop = $this->createLoop(); - $loop->addTimer(0.002, $this->expectCallableOnce()); + $loop->addTimer(0.005, $this->expectCallableOnce()); $start = microtime(true); $loop->run(); $end = microtime(true); - // 1 invocation should take 2ms (± 1ms due to timer inaccuracies) + // 1 invocation should take 5ms (± a few milliseconds 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); @@ -57,7 +57,7 @@ public function testAddPeriodicTimerWillBeInvokedUntilItIsCancelled() // 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->addTimer(0.350, function () use ($loop, $periodic) { $loop->cancelTimer($periodic); }); @@ -135,7 +135,7 @@ function () use (&$start) { $loop->run(); $end = \microtime(true); - // 1ms should be enough even on slow machines - $this->assertLessThan(0.001, $end - $start); + // 1ms should be enough even on slow machines (± 1ms due to timer inaccuracies) + $this->assertLessThan(0.002, $end - $start); } } diff --git a/travis-init.sh b/travis-init.sh deleted file mode 100755 index 94ec4f36..00000000 --- a/travis-init.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -set -e -set -o pipefail - -# install 'event' and 'ev' PHP extension on PHP 5.4+ only -if [[ "$TRAVIS_PHP_VERSION" != "5.3" ]]; then - echo "yes" | pecl install event - echo "yes" | pecl install ev -fi - -# install 'libevent' PHP extension on legacy PHP 5 only -if [[ "$TRAVIS_PHP_VERSION" < "7.0" ]]; then - curl http://pecl.php.net/get/libevent-0.1.0.tgz | tar -xz - pushd libevent-0.1.0 - phpize - ./configure - make - make install - popd - echo "extension=libevent.so" >> "$(php -r 'echo php_ini_loaded_file();')" -fi - -# install 'libev' PHP extension on legacy PHP 5 only -if [[ "$TRAVIS_PHP_VERSION" < "7.0" ]]; then - git clone --recursive https://github.com/m4rw3r/php-libev - pushd php-libev - phpize - ./configure --with-libev - make - make install - popd - echo "extension=libev.so" >> "$(php -r 'echo php_ini_loaded_file();')" -fi - -# install 'libuv' PHP extension on PHP 7+ only -if ! [[ "$TRAVIS_PHP_VERSION" < "7.0" ]]; then - echo "yes" | pecl install uv-beta -fi