mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
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.
This commit is contained in:
parent
92678d1a83
commit
2d51267c07
5 changed files with 74 additions and 123 deletions
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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--
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
?>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue