diff options
author | Mitch Hagstrand <mhagstrand@gmail.com> | 2016-12-23 12:07:47 -0800 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2016-12-27 21:52:05 +0100 |
commit | 2d51267c07123d96353bce9b7c84b26d920674f7 (patch) | |
tree | a5ef0add3f832f0ded6851f5d9692253aa02e088 | |
parent | 92678d1a83656acccee9be760ebdf90f97750dc2 (diff) | |
download | php-git-2d51267c07123d96353bce9b7c84b26d920674f7.tar.gz |
Makes the sapi web server and curl tests more reliable
1. Increased the time for the sapi/cli/tests/php_cli_server.inc to accept connections.
2. sapi/cli/tests/php_cli_server.inc has errors messages and a `stop` function.
3. bug67429.phpt uses the `stop` function to shutdown the webserver before starting a new one.
4. Removed ext/curl/tests/bug48203_multi-win32.phpt test now that ext/curl/tests/bug48203_multi.phpt
runs on Windows also.
-rw-r--r-- | ext/curl/tests/bug48203_multi-win32.phpt | 89 | ||||
-rw-r--r-- | ext/curl/tests/bug48203_multi.phpt | 30 | ||||
-rw-r--r-- | ext/curl/tests/server.inc | 4 | ||||
-rw-r--r-- | sapi/cli/tests/bug67429.phpt | 7 | ||||
-rw-r--r-- | sapi/cli/tests/php_cli_server.inc | 67 |
5 files changed, 74 insertions, 123 deletions
diff --git a/ext/curl/tests/bug48203_multi-win32.phpt b/ext/curl/tests/bug48203_multi-win32.phpt deleted file mode 100644 index 9016725080..0000000000 --- a/ext/curl/tests/bug48203_multi-win32.phpt +++ /dev/null @@ -1,89 +0,0 @@ ---TEST-- -Variation of bug #48203 with curl_multi_exec (Crash when file pointers passed to curl are closed before calling curl_multi_exec) ---SKIPIF-- -<?php -include 'skipif.inc'; -if(substr(PHP_OS, 0, 3) != 'WIN' ) { - die('skip Windows only test'); -} -?> ---FILE-- -<?php -include 'server.inc'; -function checkForClosedFilePointer($curl_option, $description) { - $fp = fopen(dirname(__FILE__) . '/bug48203.tmp', 'w'); - - $ch1 = curl_init(); - $ch2 = curl_init(); - - $options = array( - CURLOPT_RETURNTRANSFER => 1, - $curl_option => $fp, - CURLOPT_URL => curl_cli_server_start() - ); - - // we also need to set CURLOPT_VERBOSE to test CURLOPT_STDERR properly - if (CURLOPT_STDERR == $curl_option) { - $options[CURLOPT_VERBOSE] = 1; - } - - if (CURLOPT_INFILE == $curl_option) { - $options[CURLOPT_UPLOAD] = 1; - } - - curl_setopt_array($ch1, $options); - curl_setopt_array($ch2, $options); - - fclose($fp); // <-- premature close of $fp caused a crash! - - $mh = curl_multi_init(); - - curl_multi_add_handle($mh, $ch1); - curl_multi_add_handle($mh, $ch2); - - $active = 0; - do { - curl_multi_exec($mh, $active); - } while ($active > 0); - - curl_multi_remove_handle($mh, $ch1); - curl_multi_remove_handle($mh, $ch2); - curl_multi_close($mh); - - echo "Ok for $description\n"; -} - -$options_to_check = array( - "CURLOPT_STDERR", "CURLOPT_WRITEHEADER", "CURLOPT_FILE", "CURLOPT_INFILE" -); - -foreach($options_to_check as $option) { - checkForClosedFilePointer(constant($option), $option); -} - -?> ---CLEAN-- -<?php @unlink(dirname(__FILE__) . '/bug48203.tmp'); ?> ---EXPECTF-- -Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %s on line %d - -Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %s on line %d -Ok for CURLOPT_STDERR -%A - -Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %s on line %d - -Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %s on line %d -Ok for CURLOPT_WRITEHEADER - -Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %s on line %d - -Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %s on line %d -Hello World! -Hello World!Hello World! -Hello World!Ok for CURLOPT_FILE - -Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %s on line %d - -Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %s on line %d -Ok for CURLOPT_INFILE diff --git a/ext/curl/tests/bug48203_multi.phpt b/ext/curl/tests/bug48203_multi.phpt index ed09ed02ce..5f9e2ba6b2 100644 --- a/ext/curl/tests/bug48203_multi.phpt +++ b/ext/curl/tests/bug48203_multi.phpt @@ -3,9 +3,6 @@ Variation of bug #48203 with curl_multi_exec (Crash when file pointers passed to --SKIPIF-- <?php include 'skipif.inc'; -if(substr(PHP_OS, 0, 3) == 'WIN' ) { - die('skip not for Windows'); -} ?> --FILE-- <?php @@ -50,6 +47,10 @@ function checkForClosedFilePointer($target_url, $curl_option, $description) { curl_multi_remove_handle($mh, $ch2); curl_multi_close($mh); + // Force curl to output results + fflush(STDERR); + fflush(STDOUT); + echo "Ok for $description\n"; } @@ -66,24 +67,25 @@ foreach($options_to_check as $option) { --CLEAN-- <?php @unlink(dirname(__FILE__) . '/bug48203.tmp'); ?> --EXPECTF-- -Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %sbug48203_multi.php on line 36 +Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %s on line %d -Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %sbug48203_multi.php on line 36 +Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %s on line %d %A Ok for CURLOPT_STDERR -%A -Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %sbug48203_multi.php on line 36 -Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %sbug48203_multi.php on line 36 +Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %s on line %d + +Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %s on line %d Ok for CURLOPT_WRITEHEADER -Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36 +Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %s on line %d -Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36 -%AOk for CURLOPT_FILE +Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %s on line %d +Hello World! +Hello World!Hello World! +Hello World!Ok for CURLOPT_FILE -Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36 +Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %s on line %d -Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36 +Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %s on line %d Ok for CURLOPT_INFILE - diff --git a/ext/curl/tests/server.inc b/ext/curl/tests/server.inc index 62f9a2d30c..315fd68cc4 100644 --- a/ext/curl/tests/server.inc +++ b/ext/curl/tests/server.inc @@ -56,7 +56,7 @@ function curl_cli_server_start() { if ($error) { echo $error; - proc_close($handle); + proc_terminate($handle); exit(1); } @@ -65,7 +65,7 @@ function curl_cli_server_start() { proc_terminate($handle); }, $handle - ); + ); return PHP_CURL_SERVER_ADDRESS; } diff --git a/sapi/cli/tests/bug67429.phpt b/sapi/cli/tests/bug67429.phpt index 856946b29d..1c861be899 100644 --- a/sapi/cli/tests/bug67429.phpt +++ b/sapi/cli/tests/bug67429.phpt @@ -8,8 +8,9 @@ include "skipif.inc"; <?php include "php_cli_server.inc"; +// This creates a new server for each response code foreach ([308, 426] as $code) { - php_cli_server_start(<<<PHP + $proc_handle = php_cli_server_start(<<<PHP http_response_code($code); PHP ); @@ -34,6 +35,10 @@ HEADER } fclose($fp); + // Shutdown the servers or another server may not be able to start + // because of the this server still being bound to the port + + php_cli_server_stop($proc_handle); } ?> --EXPECTF-- diff --git a/sapi/cli/tests/php_cli_server.inc b/sapi/cli/tests/php_cli_server.inc index 6b1e90c4dc..6e7b70cb60 100644 --- a/sapi/cli/tests/php_cli_server.inc +++ b/sapi/cli/tests/php_cli_server.inc @@ -33,29 +33,62 @@ function php_cli_server_start($code = 'echo "Hello world";', $router = 'index.ph $handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root); } - - // note: even when server prints 'Listening on localhost:8964...Press Ctrl-C to quit.' - // it might not be listening yet...need to wait until fsockopen() call returns - $i = 0; - while (($i++ < 30) && !($fp = @fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT))) { - usleep(10000); + + // note: even when server prints 'Listening on localhost:8964...Press Ctrl-C to quit.' + // it might not be listening yet...need to wait until fsockopen() call returns + $error = "Unable to connect to servers\n"; + for ($i=0; $i < 60; $i++) { + usleep(25000); // 25ms per try + $status = proc_get_status($handle); + $fp = @fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT); + // Failure, the server is no longer running + if (!($status && $status['running'])) { + $error = "Server is not running\n"; + break; + } + // Success, Connected to servers + if ($fp) { + $error = ''; + break; + } } if ($fp) { fclose($fp); } - register_shutdown_function( - function($handle) use($router) { - proc_terminate($handle); - @unlink(__DIR__ . "/{$router}"); - }, - $handle - ); - // don't bother sleeping, server is already up - // server can take a variable amount of time to be up, so just sleeping a guessed amount of time - // does not work. this is why tests sometimes pass and sometimes fail. to get a reliable pass - // sleeping doesn't work. + if ($error) { + echo $error; + proc_terminate($handle); + exit(1); + } + + register_shutdown_function( + function($handle) use($router) { + proc_terminate($handle); + @unlink(__DIR__ . "/{$router}"); + }, + $handle + ); + + return $handle; +} + +function php_cli_server_stop($handle) { + $success = FALSE; + if ($handle) { + proc_terminate($handle); + /* Wait for server to shutdown */ + for ($i = 0; $i < 60; $i++) { + $status = proc_get_status($handle); + if (!($status && $status['running'])) { + $success = TRUE; + break; + } + usleep(25000); + } + } + return $success; } ?> |