tests: switch from pecl-ev to pecl-event
authorMichael Wallner <mike@php.net>
Fri, 22 Mar 2019 13:21:34 +0000 (14:21 +0100)
committerMichael Wallner <mike@php.net>
Fri, 22 Mar 2019 13:21:34 +0000 (14:21 +0100)
.travis.yml
scripts/gen_travis_yml.php
tests/client029.phpt

index b1a905f..8f19d08 100644 (file)
@@ -28,10 +28,10 @@ env:
  - PHP=7.2 enable_debug=yes enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes
  - PHP=master enable_debug=yes enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes
  - PHP=7.3 with_http_libicu_dir=no with_http_libidn_dir=no with_http_libidn2_dir=no with_http_libcurl_dir=no with_http_libevent_dir=no with_http_libbrotli_dir=no
- - PHP=7.3 enable_debug=no enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=7.3 enable_debug=yes enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=7.3 enable_debug=no enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=7.3 enable_debug=yes enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes
+ - PHP=7.3 PECL_EVENT=yes enable_debug=no enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes
+ - PHP=7.3 PECL_EVENT=yes enable_debug=yes enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes
+ - PHP=7.3 PECL_EVENT=yes enable_debug=no enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes
+ - PHP=7.3 PECL_EVENT=yes enable_debug=yes enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes
  - CFLAGS='-O0 -g --coverage' CXXFLAGS='-O0 -g --coverage' PHP=7.3 enable_json=yes enable_hash=yes enable_iconv=yes with_http_libicu_dir=yes with_http_libidn_dir=no with_http_libidn2_dir=no 
  - CFLAGS='-O0 -g --coverage' CXXFLAGS='-O0 -g --coverage' PHP=7.3 enable_json=yes enable_hash=yes enable_iconv=yes with_http_libidn_dir=yes with_http_libicu_dir=no with_http_libidn2_dir=no 
  - CFLAGS='-O0 -g --coverage' CXXFLAGS='-O0 -g --coverage' PHP=7.3 enable_json=yes enable_hash=yes enable_iconv=yes with_http_libidn2_dir=yes with_http_libicu_dir=no with_http_libidn_dir=no 
@@ -51,6 +51,10 @@ install:
  - make -f travis/pecl/Makefile php || make -f travis/pecl/Makefile clean php
  - make -f travis/pecl/Makefile pecl PECL=ext-raphf.git:raphf:master
  - make -f travis/pecl/Makefile pecl PECL=ext-propro.git:propro:master
+ - |
+   if test "$PECL_EVENT" = "yes"; then \
+     make -f travis/pecl/Makefile pecl PECL=event; \
+   fi
 
 script:
  - make -f travis/pecl/Makefile ext PECL=http
index 2f32a74..0549996 100755 (executable)
@@ -48,6 +48,7 @@ $env = $gen([
 ], [
 // everything enabled for current, switching debug/zts
        "PHP" => $cur,
+       "PECL_EVENT" => "yes",
        "enable_debug",
        "enable_maintainer_zts",
        "enable_json" => "yes",
@@ -96,6 +97,10 @@ install:
  - make -f travis/pecl/Makefile php || make -f travis/pecl/Makefile clean php
  - make -f travis/pecl/Makefile pecl PECL=ext-raphf.git:raphf:master
  - make -f travis/pecl/Makefile pecl PECL=ext-propro.git:propro:master
+ - |
+   if test "$PECL_EVENT" = "yes"; then \
+     make -f travis/pecl/Makefile pecl PECL=event; \
+   fi
 
 script:
  - make -f travis/pecl/Makefile ext PECL=http
index 1c8dc4f..34ca706 100644 (file)
@@ -4,24 +4,23 @@ client curl user handler
 <?php 
 include "skipif.inc";
 skip_client_test();
-_ext("ev");
-
+_ext("event");
 ?> 
---XFAIL--
-ext-ev leaks
 --FILE--
 <?php 
 echo "Test\n";
 
 class UserHandler implements http\Client\Curl\User
 {
+       private $evbase;
        private $client;
        private $run;
        private $ios = [];
        private $timeout;
 
 
-       function __construct(http\Client $client) {
+       function __construct(http\Client $client, EventBase $evbase) {
+               $this->evbase = $evbase;
                $this->client = $client;
        }
        
@@ -32,17 +31,17 @@ class UserHandler implements http\Client\Curl\User
        function timer(int $timeout_ms) {
                echo "T";
                if (isset($this->timeout)) {
-                       $this->timeout->set($timeout_ms/1000, 0);
-                       $this->timeout->start();
+                       $this->timeout->add($timeout_ms/1000);
                } else {
-                       $this->timeout = new EvTimer($timeout_ms/1000, 0, function() {
+                       $this->timeout = Event::timer($this->evbase, function() {
                                if (!call_user_func($this->run, $this->client)) {
                                        if ($this->timeout) {
-                                               $this->timeout->stop();
+                                               $this->timeout->del();
                                                $this->timeout = null;
                                        }
                                }
                        });
+                       $this->timeout->add($timeout_ms/1000);
                }
        }
        
@@ -55,7 +54,7 @@ class UserHandler implements http\Client\Curl\User
                case self::POLL_REMOVE:
                        if (isset($this->ios[(int) $socket])) {
                                echo "U";
-                               $this->ios[(int) $socket]->stop();
+                               $this->ios[(int) $socket]->del();
                                unset($this->ios[(int) $socket]);
                        }
                        break;
@@ -63,44 +62,50 @@ class UserHandler implements http\Client\Curl\User
                default:
                        $ev = 0;
                        if ($action & self::POLL_IN) {
-                               $ev |= Ev::READ;
+                               $ev |= Event::READ;
                        }
                        if ($action & self::POLL_OUT) {
-                               $ev |= Ev::WRITE;
+                               $ev |= Event::WRITE;
                        }
                        if (isset($this->ios[(int) $socket])) {
-                               $this->ios[(int) $socket]->set($socket, $ev);
+                               $this->ios[(int) $socket]->set($this->evbase, 
+                                               $socket, $ev, $this->onEvent($socket));
                        } else {
-                               $this->ios[(int) $socket] = new EvIo($socket, $ev, function($watcher, $events) use($socket) {
-                                       $action = 0;
-                                       if ($events & Ev::READ) {
-                                               $action |= self::POLL_IN;
-                                       }
-                                       if ($events & Ev::WRITE) {
-                                               $action |= self::POLL_OUT;
-                                       }
-                                       if (!call_user_func($this->run, $this->client, $socket, $action)) {
-                                               if ($this->timeout) {
-                                                       $this->timeout->stop();
-                                                       $this->timeout = null;
-                                               }
-                                       }
-                               });
+                               $this->ios[(int) $socket] = new Event($this->evbase, 
+                                               $socket, $ev, $this->onEvent($socket));
                        }
                        break;
                }
        }
        
+       function onEvent($socket) {
+               return function($watcher, $events) use($socket) {
+                       $action = 0;
+                       if ($events & Ev::READ) {
+                               $action |= self::POLL_IN;
+                       }
+                       if ($events & Ev::WRITE) {
+                               $action |= self::POLL_OUT;
+                       }
+                       if (!call_user_func($this->run, $this->client, $socket, $action)) {
+                               if ($this->timeout) {
+                                       $this->timeout->del();
+                                       $this->timeout = null;
+                               }
+                       }
+               };
+       }
+       
        function once() {
-               throw new BadMethodCallException("this test uses Ev::run()");
+               throw new BadMethodCallException("this test uses EventBase::loop()");
        }
        
        function wait(int $timeout_ms = null) {
-               throw new BadMethodCallException("this test uses Ev::run()");
+               throw new BadMethodCallException("this test uses EventBase::loop()");
        }
        
        function send() {
-               throw new BadMethodCallException("this test uses Ev::run()");
+               throw new BadMethodCallException("this test uses EventBase::loop()");
        }
 }
 
@@ -108,19 +113,20 @@ class UserHandler implements http\Client\Curl\User
 include "helper/server.inc";
 
 server("proxy.inc", function($port) {
+       $evbase = new EventBase;
        $client = new http\Client;
        $client->configure([
-                       "use_eventloop" => new UserHandler($client)
+                       "use_eventloop" => new UserHandler($client, $evbase)
        ]);
        $client->enqueue(new http\Client\Request("GET", "http://localhost:$port/"), function($r) {
                var_dump($r->getResponseCode());
        });
-       Ev::run();
+       $evbase->loop();
 });
 
 ?>
 ===DONE===
 --EXPECTREGEX--
 Test
-T[ST]+U+int\(200\)
+[ST]+U+int\(200\)
 ===DONE===