shein Tue, 20 Sep 2011 14:53:46 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=317059
Log: Refactored and speeded up php_cli_server tests, also get rid of test hanging on ubuntu: 1) Prepended starting the server with "exec" so proc_terminate can correctly close it (see also this note http://www.php.net/manual/en/function.proc-get-status.php#93382 for details) 2) Moved putting down the server to the shutdown function to make it independent from tests (fatal) errors 3) Moved php cli executable into the function to make tests more readable 4) changed sleep(1) to usleep(50000) (50 ms) to make tests faster - this needs more testing and if timeout is too small should be increased Bug: https://bugs.php.net/93382 (error getting bug information) Changed paths: U php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server.inc U php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_001.phpt U php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_002.phpt U php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_003.phpt U php/php-src/trunk/sapi/cli/tests/php_cli_server.inc U php/php-src/trunk/sapi/cli/tests/php_cli_server_001.phpt U php/php-src/trunk/sapi/cli/tests/php_cli_server_002.phpt U php/php-src/trunk/sapi/cli/tests/php_cli_server_003.phpt Modified: php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server.inc =================================================================== --- php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server.inc 2011-09-20 13:40:40 UTC (rev 317058) +++ php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server.inc 2011-09-20 14:53:46 UTC (rev 317059) @@ -1,7 +1,8 @@ <?php define ("PHP_CLI_SERVER_ADDRESS", "localhost:8964"); -function php_cli_server_start($php_executable, $code = 'echo "Hello world";') { +function php_cli_server_start($code = 'echo "Hello world";') { + $php_executable = getenv('TEST_PHP_EXECUTABLE'); $doc_root = __DIR__; $router = "router.php"; file_put_contents($doc_root . '/' . $router, '<?php ' . $code . ' ?>'); @@ -12,18 +13,18 @@ 2 => STDERR, ); - $cmd = "{$php_executable} -t {$doc_root} -S " . PHP_CLI_SERVER_ADDRESS . " {$router}"; + $cmd = "exec {$php_executable} -t {$doc_root} -S " . PHP_CLI_SERVER_ADDRESS . " {$router}"; $handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root); - sleep(1); - return $handle; -} + register_shutdown_function( + function($handle) { + proc_terminate($handle); + @unlink(__DIR__ . "/router.php"); + }, + $handle + ); -function php_cli_server_shutdown($handle) { - proc_terminate($handle); - proc_close($handle); - @unlink(__DIR__ . "router.php"); - return true; + usleep(50000); } ?> Modified: php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_001.phpt =================================================================== --- php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_001.phpt 2011-09-20 13:40:40 UTC (rev 317058) +++ php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_001.phpt 2011-09-20 14:53:46 UTC (rev 317059) @@ -12,10 +12,8 @@ --FILE-- <?php include "php_cli_server.inc"; -$php = getenv('TEST_PHP_EXECUTABLE'); -$handle = php_cli_server_start($php); +php_cli_server_start(); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS)); -php_cli_server_shutdown($handle); ?> ---EXPECT-- +--EXPECT-- string(11) "Hello world" Modified: php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_002.phpt =================================================================== --- php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_002.phpt 2011-09-20 13:40:40 UTC (rev 317058) +++ php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_002.phpt 2011-09-20 14:53:46 UTC (rev 317059) @@ -12,10 +12,8 @@ --FILE-- <?php include "php_cli_server.inc"; -$php = getenv('TEST_PHP_EXECUTABLE'); -$handle = php_cli_server_start($php, 'var_dump($_SERVER["DOCUMENT_ROOT"], $_SERVER["SERVER_SOFTWARE"]);'); +php_cli_server_start('var_dump($_SERVER["DOCUMENT_ROOT"], $_SERVER["SERVER_SOFTWARE"]);'); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS)); -php_cli_server_shutdown($handle); ?> --EXPECTF-- string(%d) "string(%d) "%s/tests" Modified: php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_003.phpt =================================================================== --- php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_003.phpt 2011-09-20 13:40:40 UTC (rev 317058) +++ php/php-src/branches/PHP_5_4/sapi/cli/tests/php_cli_server_003.phpt 2011-09-20 14:53:46 UTC (rev 317059) @@ -12,11 +12,9 @@ --FILE-- <?php include "php_cli_server.inc"; -$php = getenv('TEST_PHP_EXECUTABLE'); -$handle = php_cli_server_start($php, 'chdir("/tmp"); echo "okey";'); +php_cli_server_start('chdir("/tmp"); echo "okey";'); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS)); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS)); -php_cli_server_shutdown($handle); ?> --EXPECTF-- string(4) "okey" Modified: php/php-src/trunk/sapi/cli/tests/php_cli_server.inc =================================================================== --- php/php-src/trunk/sapi/cli/tests/php_cli_server.inc 2011-09-20 13:40:40 UTC (rev 317058) +++ php/php-src/trunk/sapi/cli/tests/php_cli_server.inc 2011-09-20 14:53:46 UTC (rev 317059) @@ -1,7 +1,8 @@ <?php define ("PHP_CLI_SERVER_ADDRESS", "localhost:8964"); -function php_cli_server_start($php_executable, $code = 'echo "Hello world";') { +function php_cli_server_start($code = 'echo "Hello world";') { + $php_executable = getenv('TEST_PHP_EXECUTABLE'); $doc_root = __DIR__; $router = "router.php"; file_put_contents($doc_root . '/' . $router, '<?php ' . $code . ' ?>'); @@ -12,18 +13,18 @@ 2 => STDERR, ); - $cmd = "{$php_executable} -t {$doc_root} -S " . PHP_CLI_SERVER_ADDRESS . " {$router}"; + $cmd = "exec {$php_executable} -t {$doc_root} -S " . PHP_CLI_SERVER_ADDRESS . " {$router}"; $handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root); - sleep(1); - return $handle; -} + register_shutdown_function( + function($handle) { + proc_terminate($handle); + @unlink(__DIR__ . "/router.php"); + }, + $handle + ); -function php_cli_server_shutdown($handle) { - proc_terminate($handle); - proc_close($handle); - @unlink(__DIR__ . "router.php"); - return true; + usleep(50000); } ?> Modified: php/php-src/trunk/sapi/cli/tests/php_cli_server_001.phpt =================================================================== --- php/php-src/trunk/sapi/cli/tests/php_cli_server_001.phpt 2011-09-20 13:40:40 UTC (rev 317058) +++ php/php-src/trunk/sapi/cli/tests/php_cli_server_001.phpt 2011-09-20 14:53:46 UTC (rev 317059) @@ -12,10 +12,8 @@ --FILE-- <?php include "php_cli_server.inc"; -$php = getenv('TEST_PHP_EXECUTABLE'); -$handle = php_cli_server_start($php); +php_cli_server_start(); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS)); -php_cli_server_shutdown($handle); ?> ---EXPECT-- +--EXPECT-- string(11) "Hello world" Modified: php/php-src/trunk/sapi/cli/tests/php_cli_server_002.phpt =================================================================== --- php/php-src/trunk/sapi/cli/tests/php_cli_server_002.phpt 2011-09-20 13:40:40 UTC (rev 317058) +++ php/php-src/trunk/sapi/cli/tests/php_cli_server_002.phpt 2011-09-20 14:53:46 UTC (rev 317059) @@ -12,10 +12,8 @@ --FILE-- <?php include "php_cli_server.inc"; -$php = getenv('TEST_PHP_EXECUTABLE'); -$handle = php_cli_server_start($php, 'var_dump($_SERVER["DOCUMENT_ROOT"], $_SERVER["SERVER_SOFTWARE"]);'); +php_cli_server_start('var_dump($_SERVER["DOCUMENT_ROOT"], $_SERVER["SERVER_SOFTWARE"]);'); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS)); -php_cli_server_shutdown($handle); ?> --EXPECTF-- string(%d) "string(%d) "%s/tests" Modified: php/php-src/trunk/sapi/cli/tests/php_cli_server_003.phpt =================================================================== --- php/php-src/trunk/sapi/cli/tests/php_cli_server_003.phpt 2011-09-20 13:40:40 UTC (rev 317058) +++ php/php-src/trunk/sapi/cli/tests/php_cli_server_003.phpt 2011-09-20 14:53:46 UTC (rev 317059) @@ -12,11 +12,9 @@ --FILE-- <?php include "php_cli_server.inc"; -$php = getenv('TEST_PHP_EXECUTABLE'); -$handle = php_cli_server_start($php, 'chdir("/tmp"); echo "okey";'); +php_cli_server_start('chdir("/tmp"); echo "okey";'); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS)); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS)); -php_cli_server_shutdown($handle); ?> --EXPECTF-- string(4) "okey"
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php