From: Shein Alexey Date: Tue, 20 Sep 2011 14:53:46 +0000 (+0000) Subject: Refactored and speeded up php_cli_server tests, also get rid of test hanging on ubuntu: X-Git-Tag: php-5.4.0beta2~97 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c365dc3eff3867ce093bb4cabb9142e76fee0ce;p=php 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 --- diff --git a/sapi/cli/tests/php_cli_server.inc b/sapi/cli/tests/php_cli_server.inc index 012efa704f..3a4e8ebb17 100644 --- a/sapi/cli/tests/php_cli_server.inc +++ b/sapi/cli/tests/php_cli_server.inc @@ -1,7 +1,8 @@ '); @@ -12,18 +13,18 @@ function php_cli_server_start($php_executable, $code = 'echo "Hello world";') { 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); } ?> diff --git a/sapi/cli/tests/php_cli_server_001.phpt b/sapi/cli/tests/php_cli_server_001.phpt index 30d72700ba..27c81bb6ba 100644 --- a/sapi/cli/tests/php_cli_server_001.phpt +++ b/sapi/cli/tests/php_cli_server_001.phpt @@ -12,10 +12,8 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { --FILE-- ---EXPECT-- +--EXPECT-- string(11) "Hello world" diff --git a/sapi/cli/tests/php_cli_server_002.phpt b/sapi/cli/tests/php_cli_server_002.phpt index 046dd731c1..e1120d61bf 100644 --- a/sapi/cli/tests/php_cli_server_002.phpt +++ b/sapi/cli/tests/php_cli_server_002.phpt @@ -12,10 +12,8 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { --FILE-- --EXPECTF-- string(%d) "string(%d) "%s/tests" diff --git a/sapi/cli/tests/php_cli_server_003.phpt b/sapi/cli/tests/php_cli_server_003.phpt index 0fe104ff6a..8e7f11fed7 100644 --- a/sapi/cli/tests/php_cli_server_003.phpt +++ b/sapi/cli/tests/php_cli_server_003.phpt @@ -12,11 +12,9 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { --FILE-- --EXPECTF-- string(4) "okey"