reduce count of online tests
authorMichael Wallner <mike@php.net>
Wed, 11 Feb 2015 15:11:46 +0000 (16:11 +0100)
committerMichael Wallner <mike@php.net>
Wed, 11 Feb 2015 15:11:46 +0000 (16:11 +0100)
21 files changed:
tests/client001.phpt
tests/client002.phpt
tests/client003.phpt
tests/client004.phpt
tests/client005.phpt
tests/client006.phpt
tests/client007.phpt
tests/client008.phpt
tests/client009.phpt
tests/client010.phpt
tests/client011.phpt
tests/client012.phpt
tests/client013.phpt
tests/client014.phpt
tests/client015.phpt
tests/client016.phpt
tests/clientresponse001.phpt
tests/clientresponse002.phpt
tests/clientresponse003.phpt
tests/proxy002.phpt
tests/server.inc

index 8071afa..dea89a8 100644 (file)
@@ -3,6 +3,7 @@ client drivers
 --SKIPIF--
 <?php
 include "skipif.inc";
+skip_client_test();
 ?>
 --FILE--
 <?php
index 89d4d65..e07b82e 100644 (file)
@@ -3,10 +3,13 @@ client observer
 --SKIPIF--
 <?php
 include "skipif.inc";
-skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
+
+include "server.inc";
+
 echo "Test\n";
 
 class Observer implements SplObserver
@@ -19,15 +22,14 @@ class Observer implements SplObserver
        }
 }
 
-$observer = new Observer;
-$request = new http\Client\Request("GET", "http://www.example.org/");
-
-foreach (http\Client::getAvailableDrivers() as $driver) {
-       $client = new http\Client($driver);
-       $client->attach($observer);
-       $client->enqueue($request);
-       $client->send();
-}
+server("proxy.inc", function($port, $stdin, $stdout, $stderr) {
+       foreach (http\Client::getAvailableDrivers() as $driver) {
+               $client = new http\Client($driver);
+               $client->attach(new Observer);
+               $client->enqueue(new http\Client\Request("GET", "http://localhost:$port/"));
+               $client->send();
+       }
+});
 
 ?>
 
index 62d0bca..29ab245 100644 (file)
@@ -3,26 +3,31 @@ client once & wait
 --SKIPIF--
 <?php
 include "skipif.inc";
-skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
-echo "Test\n";
 
-$request = new http\Client\Request("GET", "http://www.example.org/");
+include "server.inc";
+
+echo "Test\n";
 
-foreach (http\Client::getAvailableDrivers() as $driver) {
-       $client = new http\Client($driver);
-       $client->enqueue($request);
+server("proxy.inc", function($port) {
+       $request = new http\Client\Request("GET", "http://www.example.org/");
        
-       while ($client->once()) {
-               $client->wait(.1);
-       }
+       foreach (http\Client::getAvailableDrivers() as $driver) {
+               $client = new http\Client($driver);
+               $client->enqueue($request);
+       
+               while ($client->once()) {
+                       $client->wait(.1);
+               }
        
-       if (!$client->getResponse()) {
-               var_dump($client);
+               if (!$client->getResponse()) {
+                       var_dump($client);
+               }
        }
-}
+});
 ?>
 Done
 --EXPECT--
index 1342efa..204e172 100644 (file)
@@ -3,31 +3,36 @@ client reset
 --SKIPIF--
 <?php
 include "skipif.inc";
-skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
-echo "Test\n";
 
-$request = new http\Client\Request("GET", "http://www.example.org");
+include "server.inc";
 
-foreach (http\Client::getAvailableDrivers() as $driver) {
-       $client = new http\Client($driver);
-       $client->enqueue($request)->send();
-       if (!($client->getResponse($request) instanceof http\Client\Response)) {
-               var_dump($client);
-       }
-       try {
+echo "Test\n";
+
+server("proxy.inc", function($port) {
+       $request = new http\Client\Request("GET", "http://localhost:$port");
+       
+       foreach (http\Client::getAvailableDrivers() as $driver) {
+               $client = new http\Client($driver);
+               $client->enqueue($request)->send();
+               if (!($client->getResponse($request) instanceof http\Client\Response)) {
+                       var_dump($client);
+               }
+               try {
+                       $client->enqueue($request);
+               } catch (Exception $e) {
+                       echo $e->getMessage(),"\n";
+               }
+               $client->reset();
+               if (($response = $client->getResponse())) {
+                       var_dump($response);
+               }
                $client->enqueue($request);
-       } catch (Exception $e) {
-               echo $e->getMessage(),"\n";
-       }
-       $client->reset();
-       if (($response = $client->getResponse())) {
-               var_dump($response);
        }
-       $client->enqueue($request);
-}
+       });
 ?>
 Done
 --EXPECTREGEX--
index 4576f16..229195c 100644 (file)
@@ -3,22 +3,27 @@ client response callback
 --SKIPIF--
 <?php
 include "skipif.inc";
-skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
+
+include "server.inc";
+
 echo "Test\n";
 
-foreach (http\Client::getAvailableDrivers() as $driver) {
-       $client = new http\Client($driver);
-       $client->enqueue(new http\Client\Request("GET", "http://www.example.org"), function($response) {
-               echo "R\n";
-               if (!($response instanceof http\Client\Response)) {
-                       var_dump($response);
-               }
-       });
-       $client->send();
-}
+server("proxy.inc", function($port) {
+       foreach (http\Client::getAvailableDrivers() as $driver) {
+               $client = new http\Client($driver);
+               $client->enqueue(new http\Client\Request("GET", "http://localhost:$port"), function($response) {
+                       echo "R\n";
+                       if (!($response instanceof http\Client\Response)) {
+                               var_dump($response);
+                       }
+               });
+               $client->send();
+       }
+});
 
 ?>
 Done
index 7b3986e..403d3e7 100644 (file)
@@ -3,10 +3,13 @@ client response callback + dequeue
 --SKIPIF--
 <?php
 include "skipif.inc";
-skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
+
+include "server.inc";
+
 echo "Test\n";
 
 function response($response) {
@@ -19,20 +22,22 @@ function response($response) {
        return true;
 }
 
-$request = new http\Client\Request("GET", "http://www.example.org");
-
-foreach (http\Client::getAvailableDrivers() as $driver) {
-       $client = new http\Client($driver);
-       for ($i=0; $i < 2; ++ $i) {
-               $client->enqueue($request, "response");
-               $client->send();
-               try {
-                       $client->dequeue($request);
-               } catch (Exception $e) {
-                       echo $e->getMessage(),"\n";
+server("proxy.inc", function($port) {
+       $request = new http\Client\Request("GET", "http://localhost:$port");
+       
+       foreach (http\Client::getAvailableDrivers() as $driver) {
+               $client = new http\Client($driver);
+               for ($i=0; $i < 2; ++ $i) {
+                       $client->enqueue($request, "response");
+                       $client->send();
+                       try {
+                               $client->dequeue($request);
+                       } catch (Exception $e) {
+                               echo $e->getMessage(),"\n";
+                       }
                }
        }
-}
+});
 
 ?>
 Done
index 74cdbcd..6383567 100644 (file)
@@ -3,10 +3,13 @@ client response callback + requeue
 --SKIPIF--
 <?php
 include "skipif.inc";
-skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
+
+include "server.inc";
+
 echo "Test\n";
 
 function response($response) {
@@ -16,15 +19,17 @@ function response($response) {
        }
 }
 
-$request = new http\Client\Request("GET", "http://www.example.org");
-
-foreach (http\Client::getAvailableDrivers() as $driver) {
-       $client = new http\Client($driver);
-       for ($i=0; $i < 2; ++ $i) {
-               $client->requeue($request, "response");
-               $client->send();
+server("proxy.inc", function($port) {
+       $request = new http\Client\Request("GET", "http://localhost:$port");
+       
+       foreach (http\Client::getAvailableDrivers() as $driver) {
+               $client = new http\Client($driver);
+               for ($i=0; $i < 2; ++ $i) {
+                       $client->requeue($request, "response");
+                       $client->send();
+               }
        }
-}
+});
 
 ?>
 Done
index 2585f23..41c3e68 100644 (file)
@@ -3,28 +3,35 @@ client features
 --SKIPIF--
 <?php
 include "skipif.inc";
-skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
-echo "Test\n";
 
-$request = new http\Client\Request("GET", "http://www.example.org");
+include "server.inc";
 
-foreach (http\Client::getAvailableDrivers() as $driver) {
-       $client = new http\Client($driver);
-       $client->configure(["pipelining" => true, "use_eventloop" => true]);
+echo "Test\n";
+
+server("pipeline.inc", function($port, $stdin) {
+       fputs($stdin, "2\n");
        
+       $request = new http\Client\Request("GET", "http://localhost:$port");
+       
+       $client = new http\Client();
+       $client->configure(["pipelining" => true, "use_eventloop" => true]);
+
        $client->enqueue($request);
+       $client->send();
+       
        $client->enqueue(clone $request);
        $client->enqueue(clone $request);
-       
+
        $client->send();
-       
+
        while ($client->getResponse()) {
                echo "R\n";
        }
-}
+});
 
 ?>
 Done
index e1553d6..9b5579d 100644 (file)
@@ -4,6 +4,7 @@ client static cookies
 <?php
 include "skipif.inc";
 skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
index 055d585..86f9c8c 100644 (file)
@@ -4,6 +4,7 @@ client upload
 <?php
 include "skipif.inc";
 skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
index 284edb2..5909742 100644 (file)
@@ -4,6 +4,7 @@ client history
 <?php 
 include "skipif.inc";
 skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php 
index e4c188c..8db3afc 100644 (file)
@@ -4,10 +4,10 @@ client ssl
 <?php 
 include "skipif.inc";
 skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php 
-
 echo "Test\n";
 
 $client = new http\Client;
index 00bae4e..f246a30 100644 (file)
@@ -3,11 +3,13 @@ client observers
 --SKIPIF--
 <?php 
 include "skipif.inc";
-skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php 
 
+include "server.inc";
+
 echo "Test\n";
 
 class Client extends http\Client {
@@ -33,33 +35,36 @@ class CallbackObserver implements SplObserver {
        }
 }
 
-$client = new Client;
-$client->attach($o1 = new ProgressObserver1);
-$client->attach($o2 = new ProgressObserver2);
-$client->attach(
-               $o3 = new CallbackObserver(
-                               function ($c, $r) {
-                                       $p = (array) $c->getProgressInfo($r);
-                                       var_dump(array_key_exists("started", $p));
-                                       var_dump(array_key_exists("finished", $p));
-                                       var_dump(array_key_exists("dlnow", $p));
-                                       var_dump(array_key_exists("ulnow", $p));
-                                       var_dump(array_key_exists("dltotal", $p));
-                                       var_dump(array_key_exists("ultotal", $p));
-                                       var_dump(array_key_exists("info", $p));
-                               }
-               )
-);
-
-$client->enqueue(new http\Client\Request("GET", "http://www.example.com/"))->send();
-var_dump(1 === preg_match("/(\.-)+/", $client->pi));
-var_dump(3 === count($client->getObservers()));
-$client->detach($o1);
-var_dump(2 === count($client->getObservers()));
-$client->detach($o2);
-var_dump(1 === count($client->getObservers()));
-$client->detach($o3);
-var_dump(0 === count($client->getObservers()));
+server("proxy.inc", function($port) {
+       $client = new Client;
+       $client->attach($o1 = new ProgressObserver1);
+       $client->attach($o2 = new ProgressObserver2);
+       $client->attach(
+                       $o3 = new CallbackObserver(
+                                       function ($c, $r) {
+                                               $p = (array) $c->getProgressInfo($r);
+                                               var_dump(array_key_exists("started", $p));
+                                               var_dump(array_key_exists("finished", $p));
+                                               var_dump(array_key_exists("dlnow", $p));
+                                               var_dump(array_key_exists("ulnow", $p));
+                                               var_dump(array_key_exists("dltotal", $p));
+                                               var_dump(array_key_exists("ultotal", $p));
+                                               var_dump(array_key_exists("info", $p));
+                                       }
+                       )
+       );
+       
+       $client->enqueue(new http\Client\Request("GET", "http://localhost:$port/"))->send();
+       var_dump(1 === preg_match("/(\.-)+/", $client->pi));
+       var_dump(3 === count($client->getObservers()));
+       $client->detach($o1);
+       var_dump(2 === count($client->getObservers()));
+       $client->detach($o2);
+       var_dump(1 === count($client->getObservers()));
+       $client->detach($o3);
+       var_dump(0 === count($client->getObservers()));
+       
+});
 
 ?>
 Done
index d0ff471..a4504c1 100644 (file)
@@ -3,6 +3,7 @@ reset content length when resetting body
 --SKIPIF--
 <?php 
 include "skipif.inc";
+skip_client_test();
 ?>
 --FILE--
 <?php 
index 0ab520c..a5c2ef7 100644 (file)
@@ -3,30 +3,35 @@ http client event base
 --SKIPIF--
 <?php 
 include "skipif.inc";
-skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
-echo "Test\n";
-
-$client1 = new http\Client;
-$client2 = new http\Client;
-
-$client1->configure(["use_eventloop" => true]);
-$client2->configure(["use_eventloop" => true]);
 
-$client1->enqueue(new http\Client\Request("GET", "http://www.google.ca/"));
-$client2->enqueue(new http\Client\Request("GET", "http://www.google.co.uk/"));
+include "server.inc";
 
-$client1->send();
-
-if (($r = $client1->getResponse())) {
-       var_dump($r->getTransferInfo("response_code"));
-}
-if (($r = $client2->getResponse())) {
-       var_dump($r->getTransferInfo("response_code"));
-}
+echo "Test\n";
 
+server("proxy.inc", function($port) {
+       $client1 = new http\Client;
+       $client2 = new http\Client;
+       
+       $client1->configure(["use_eventloop" => true]);
+       $client2->configure(["use_eventloop" => true]);
+       
+       $client1->enqueue(new http\Client\Request("GET", "http://localhost:$port/"));
+       $client2->enqueue(new http\Client\Request("GET", "http://localhost:$port/"));
+       
+       $client1->send();
+       
+       if (($r = $client1->getResponse())) {
+               var_dump($r->getTransferInfo("response_code"));
+       }
+       if (($r = $client2->getResponse())) {
+               var_dump($r->getTransferInfo("response_code"));
+       }
+       
+});
 ?>
 DONE
 --EXPECT--
index 5fda0b6..c935f06 100644 (file)
@@ -3,27 +3,32 @@ client once & wait with events
 --SKIPIF--
 <?php
 include "skipif.inc";
-skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
-echo "Test\n";
 
-$request = new http\Client\Request("GET", "http://www.example.org/");
+include "server.inc";
+
+echo "Test\n";
 
-foreach (http\Client::getAvailableDrivers() as $driver) {
-       $client = new http\Client($driver);
-       $client->configure(["use_eventloop" => true]);
-       $client->enqueue($request);
+server("proxy.inc", function($port) {
+       $request = new http\Client\Request("GET", "http://localhost:$port/");
        
-       while ($client->once()) {
-               $client->wait(.1);
-       }
+       foreach (http\Client::getAvailableDrivers() as $driver) {
+               $client = new http\Client($driver);
+               $client->configure(["use_eventloop" => true]);
+               $client->enqueue($request);
+       
+               while ($client->once()) {
+                       $client->wait(.1);
+               }
        
-       if (!$client->getResponse()) {
-               var_dump($client);
+               if (!$client->getResponse()) {
+                       var_dump($client);
+               }
        }
-}
+});
 ?>
 Done
 --EXPECT--
index 270512b..705ee2e 100644 (file)
@@ -4,6 +4,7 @@ client response cookie
 <?php
 include "skipif.inc";
 skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
index 2379cc7..8c57355 100644 (file)
@@ -4,6 +4,7 @@ client response cookies
 <?php
 include "skipif.inc";
 skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
index 8ab936d..45c1d26 100644 (file)
@@ -3,20 +3,25 @@ client response transfer info
 --SKIPIF--
 <?php
 include "skipif.inc";
-skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
-echo "Test\n";
 
-$request = new http\Client\Request("GET", "http://www.example.org");
+include "server.inc";
+
+echo "Test\n";
 
-foreach (http\Client::getAvailableDrivers() as $driver) {
-       $client = new http\Client($driver);
-       $response = $client->enqueue($request)->send()->getResponse();
-       var_dump($response->getTransferInfo("response_code"));
-       var_dump(count((array)$response->getTransferInfo()));
-}
+server("proxy.inc", function($port) {
+       $request = new http\Client\Request("GET", "http://localhost:$port");
+       
+       foreach (http\Client::getAvailableDrivers() as $driver) {
+               $client = new http\Client($driver);
+               $response = $client->enqueue($request)->send()->getResponse();
+               var_dump($response->getTransferInfo("response_code"));
+               var_dump(count((array)$response->getTransferInfo()));
+       }
+});
 ?>
 Done
 --EXPECTREGEX--
index 86bee61..ce548a5 100644 (file)
@@ -8,11 +8,11 @@ skip_client_test();
 --FILE--
 <?php
 
+include "server.inc";
+
 echo "Test\n";
 
-$spec = array(array("pipe","r"), array("pipe","w"), array("pipe","w"));
-if (($proc = proc_open(PHP_BINARY . " proxy.inc", $spec, $pipes, __DIR__))) {
-       $port = trim(fgets($pipes[2]));
+server("proxy.inc", function($port, $stdin, $stdout, $stderr) {
        echo "Server on port $port\n";
        $c = new http\Client;
        $r = new http\Client\Request("GET", "http://localhost:$port/");
@@ -26,11 +26,9 @@ if (($proc = proc_open(PHP_BINARY . " proxy.inc", $spec, $pipes, __DIR__))) {
                echo $e;
        }
        echo $c->getResponse()->getBody();
-       while (!feof($pipes[1])) {
-               echo fgets($pipes[1]);
-       }
        unset($r, $client);
-}
+});
+
 ?>
 ===DONE===
 --EXPECTF--
index 304e393..ca20cb0 100644 (file)
@@ -4,9 +4,18 @@ function serve(callable $cb) {
        foreach (range(8000, 9000) as $port) {
                if (($server = stream_socket_server("tcp://localhost:$port"))) {
                        fprintf(STDERR, "%s\n", $port);
-                       if (($client = stream_socket_accept($server))) {
-                               $cb($client);
-                       }
+                       do {
+                               $R = [$server]; $W = []; $E = [];
+                               $select = stream_select($R, $E, $E, 0, 10000);
+                               if ($select && ($client = stream_socket_accept($server, 1))) {
+                                       if (getenv("PHP_HTTP_TEST_SSL")) {
+                                               stream_socket_enable_crypto($client, true, STREAM_CRYPTO_METHOD_SSLv23_SERVER);
+                                       }
+                                       while (!feof($client)) {
+                                               $cb($client);
+                                       }
+                               }
+                       } while ($select !== false);
                        return;
                }
        }
@@ -17,10 +26,9 @@ function server($file, callable $cb) {
        if (($proc = proc_open(PHP_BINARY . " $file", $spec, $pipes, __DIR__))) {
                $port = trim(fgets($pipes[2]));
                
-               $cb($port, 
-                               $stdin = $pipes[0], 
-                               $stdout = $pipes[1], 
-                               $stderr = $pipes[2]);
+               $cb($port, $stdin = $pipes[0], $stdout = $pipes[1], $stderr = $pipes[2]);
+               
+               proc_terminate($proc);
                
                fpassthru($stderr);
                fpassthru($stdout);