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 8071afa411ddbcc90389b4a610091dcdd2f6338c..dea89a84aa2788ae9b0b4c950b0c1ea67e6ef388 100644 (file)
@@ -3,6 +3,7 @@ client drivers
 --SKIPIF--
 <?php
 include "skipif.inc";
+skip_client_test();
 ?>
 --FILE--
 <?php
index 89d4d658b8a58ee2d5cfcf94cf72ca4b8c319bbe..e07b82e21669fff8e5e38e250611c8c4397993c5 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 62d0bca64be7eee3e5522918605ecdac601797ca..29ab245fd07b503c37880fcd24864b4097950a46 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 1342efaadd61601e07e08675015b532032f94b06..204e172f38e7319259d734cd40616654de0cf0a8 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 4576f16d0868785d328dd3cb8fac30dd8ca6557d..229195caa85bc11317caa6e04382ecf6074a0d07 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 7b3986e583a2703f38a6153099d4091aab9cd5f0..403d3e71d901835635beefa74973f0270e443e1c 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 74cdbcd9d06f677797338ab422a324bbd1679510..638356701a4d1fd75a274590089b4d18a8bb6953 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 2585f235d0b3e07456aee66fef8315ee12e156f7..41c3e681b9b5bc1a221b9ea46d677a11770fcaa1 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 e1553d65449240ec83a1d70875b4023c4881af5c..9b5579dc71994a80f94a6d1c9ec903c1ad99fc1f 100644 (file)
@@ -4,6 +4,7 @@ client static cookies
 <?php
 include "skipif.inc";
 skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
index 055d5855c916284eb5b146eaf05be80c38023d95..86f9c8c94da026c364e2fe557c64901c9ddbc551 100644 (file)
@@ -4,6 +4,7 @@ client upload
 <?php
 include "skipif.inc";
 skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
index 284edb25d10dac448cbd7230c328510373b02e06..59097420c72f5b35d63469a9d3fa588f4ed231af 100644 (file)
@@ -4,6 +4,7 @@ client history
 <?php 
 include "skipif.inc";
 skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php 
index e4c188c7ffd44cd8bac36c5567e859ad5ea2e4a3..8db3afcc2c3807fcfcd80c25b4ef85e4bae432d5 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 00bae4e0de5c7f7419b42c46c1240d5a1d33d9e4..f246a30c850a36a83879c14f06b6a36194c8b19d 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 d0ff4716b276786bfbd7c0a7ca80c1ddf597ac7c..a4504c1291833c70f38d5645758b137b0cc224f5 100644 (file)
@@ -3,6 +3,7 @@ reset content length when resetting body
 --SKIPIF--
 <?php 
 include "skipif.inc";
+skip_client_test();
 ?>
 --FILE--
 <?php 
index 0ab520cb75fb73b250535d1a80a17111517fcf93..a5c2ef700e1f842e7e41e656c5ee3be8e8501a9f 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 5fda0b6670cf806b0217e30541890ddc40b0f9de..c935f068ec6080b8936c01850681dc39527f6705 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 270512b358ab926c94fd2edda42d17390aa6048a..705ee2e3e173ef83c477ba260a67ed173280a851 100644 (file)
@@ -4,6 +4,7 @@ client response cookie
 <?php
 include "skipif.inc";
 skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
index 2379cc7e6ddf3e7717e373a1b365b9253dc79630..8c57355b46b016cbfc64fca948b44c83add6f6a0 100644 (file)
@@ -4,6 +4,7 @@ client response cookies
 <?php
 include "skipif.inc";
 skip_online_test();
+skip_client_test();
 ?>
 --FILE--
 <?php
index 8ab936d059b94b94b4302fe77faeada7c90676f4..45c1d26dabc76feedabb96e17f0a739095392bec 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 86bee615c8570aa53b582e2f54a7e335549716c5..ce548a54e2b8612d7c508cb078682505396d7a62 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 304e393b1ecf9382459708dbdc6c4ff47763264e..ca20cb017ddd19eb10e483afab98e201eb3b5dd0 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);