From 8a3ddf26349337c2c42dc2716bb4b3e93bded96c Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 11 Feb 2015 16:11:46 +0100 Subject: [PATCH] reduce count of online tests --- tests/client001.phpt | 1 + tests/client002.phpt | 22 +++++++------ tests/client003.phpt | 29 ++++++++++------- tests/client004.phpt | 41 +++++++++++++----------- tests/client005.phpt | 27 +++++++++------- tests/client006.phpt | 31 ++++++++++-------- tests/client007.phpt | 23 ++++++++------ tests/client008.phpt | 25 +++++++++------ tests/client009.phpt | 1 + tests/client010.phpt | 1 + tests/client011.phpt | 1 + tests/client012.phpt | 2 +- tests/client013.phpt | 61 +++++++++++++++++++----------------- tests/client014.phpt | 1 + tests/client015.phpt | 41 +++++++++++++----------- tests/client016.phpt | 31 ++++++++++-------- tests/clientresponse001.phpt | 1 + tests/clientresponse002.phpt | 1 + tests/clientresponse003.phpt | 23 ++++++++------ tests/proxy002.phpt | 12 +++---- tests/server.inc | 22 ++++++++----- 21 files changed, 232 insertions(+), 165 deletions(-) diff --git a/tests/client001.phpt b/tests/client001.phpt index 8071afa..dea89a8 100644 --- a/tests/client001.phpt +++ b/tests/client001.phpt @@ -3,6 +3,7 @@ client drivers --SKIPIF-- --FILE-- --FILE-- 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(); + } +}); ?> diff --git a/tests/client003.phpt b/tests/client003.phpt index 62d0bca..29ab245 100644 --- a/tests/client003.phpt +++ b/tests/client003.phpt @@ -3,26 +3,31 @@ client once & wait --SKIPIF-- --FILE-- 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-- diff --git a/tests/client004.phpt b/tests/client004.phpt index 1342efa..204e172 100644 --- a/tests/client004.phpt +++ b/tests/client004.phpt @@ -3,31 +3,36 @@ client reset --SKIPIF-- --FILE-- 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-- diff --git a/tests/client005.phpt b/tests/client005.phpt index 4576f16..229195c 100644 --- a/tests/client005.phpt +++ b/tests/client005.phpt @@ -3,22 +3,27 @@ client response callback --SKIPIF-- --FILE-- 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 diff --git a/tests/client006.phpt b/tests/client006.phpt index 7b3986e..403d3e7 100644 --- a/tests/client006.phpt +++ b/tests/client006.phpt @@ -3,10 +3,13 @@ client response callback + dequeue --SKIPIF-- --FILE-- 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 diff --git a/tests/client007.phpt b/tests/client007.phpt index 74cdbcd..6383567 100644 --- a/tests/client007.phpt +++ b/tests/client007.phpt @@ -3,10 +3,13 @@ client response callback + requeue --SKIPIF-- --FILE-- 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 diff --git a/tests/client008.phpt b/tests/client008.phpt index 2585f23..41c3e68 100644 --- a/tests/client008.phpt +++ b/tests/client008.phpt @@ -3,28 +3,35 @@ client features --SKIPIF-- --FILE-- 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 diff --git a/tests/client009.phpt b/tests/client009.phpt index e1553d6..9b5579d 100644 --- a/tests/client009.phpt +++ b/tests/client009.phpt @@ -4,6 +4,7 @@ client static cookies --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- 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 diff --git a/tests/client014.phpt b/tests/client014.phpt index d0ff471..a4504c1 100644 --- a/tests/client014.phpt +++ b/tests/client014.phpt @@ -3,6 +3,7 @@ reset content length when resetting body --SKIPIF-- --FILE-- --FILE-- 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-- diff --git a/tests/client016.phpt b/tests/client016.phpt index 5fda0b6..c935f06 100644 --- a/tests/client016.phpt +++ b/tests/client016.phpt @@ -3,27 +3,32 @@ client once & wait with events --SKIPIF-- --FILE-- 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-- diff --git a/tests/clientresponse001.phpt b/tests/clientresponse001.phpt index 270512b..705ee2e 100644 --- a/tests/clientresponse001.phpt +++ b/tests/clientresponse001.phpt @@ -4,6 +4,7 @@ client response cookie --FILE-- --FILE-- --FILE-- 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-- diff --git a/tests/proxy002.phpt b/tests/proxy002.phpt index 86bee61..ce548a5 100644 --- a/tests/proxy002.phpt +++ b/tests/proxy002.phpt @@ -8,11 +8,11 @@ skip_client_test(); --FILE-- getResponse()->getBody(); - while (!feof($pipes[1])) { - echo fgets($pipes[1]); - } unset($r, $client); -} +}); + ?> ===DONE=== --EXPECTF-- diff --git a/tests/server.inc b/tests/server.inc index 304e393..ca20cb0 100644 --- a/tests/server.inc +++ b/tests/server.inc @@ -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); -- 2.30.2