summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Hagstrand <mhagstrand@gmail.com>2016-12-20 02:37:48 -0800
committerNikita Popov <nikic@php.net>2016-12-27 21:52:05 +0100
commit92678d1a83656acccee9be760ebdf90f97750dc2 (patch)
treea098d169dbc3234e761ae07864db0b5d2f679be6
parent7f29e7c67897e33ab8156f87122b37928393bd1a (diff)
downloadphp-git-92678d1a83656acccee9be760ebdf90f97750dc2.tar.gz
Fixes the curl tests to be more reliable in Travis CI
1. Increases the amount of time for the PHP built-in server to accept a connection 2. Outputs an error if the PHP built-in server fails 3. In bug48203_multi.phpt the test no longer starts and stops multiple PHP built-in servers
-rw-r--r--ext/curl/tests/bug48203_multi.phpt8
-rw-r--r--ext/curl/tests/server.inc84
2 files changed, 55 insertions, 37 deletions
diff --git a/ext/curl/tests/bug48203_multi.phpt b/ext/curl/tests/bug48203_multi.phpt
index b582e78627..ed09ed02ce 100644
--- a/ext/curl/tests/bug48203_multi.phpt
+++ b/ext/curl/tests/bug48203_multi.phpt
@@ -10,7 +10,7 @@ if(substr(PHP_OS, 0, 3) == 'WIN' ) {
--FILE--
<?php
include 'server.inc';
-function checkForClosedFilePointer($curl_option, $description) {
+function checkForClosedFilePointer($target_url, $curl_option, $description) {
$fp = fopen(dirname(__FILE__) . '/bug48203.tmp', 'w');
$ch1 = curl_init();
@@ -19,7 +19,7 @@ function checkForClosedFilePointer($curl_option, $description) {
$options = array(
CURLOPT_RETURNTRANSFER => 1,
$curl_option => $fp,
- CURLOPT_URL => curl_cli_server_start()
+ CURLOPT_URL => $target_url,
);
// we also need to set CURLOPT_VERBOSE to test CURLOPT_STDERR properly
@@ -57,8 +57,9 @@ $options_to_check = array(
"CURLOPT_STDERR", "CURLOPT_WRITEHEADER", "CURLOPT_FILE", "CURLOPT_INFILE"
);
+$target_url = curl_cli_server_start();
foreach($options_to_check as $option) {
- checkForClosedFilePointer(constant($option), $option);
+ checkForClosedFilePointer($target_url, constant($option), $option);
}
?>
@@ -85,3 +86,4 @@ Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to
Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36
Ok for CURLOPT_INFILE
+
diff --git a/ext/curl/tests/server.inc b/ext/curl/tests/server.inc
index 6d96a9850c..62f9a2d30c 100644
--- a/ext/curl/tests/server.inc
+++ b/ext/curl/tests/server.inc
@@ -9,48 +9,64 @@ function curl_cli_server_start() {
return getenv('PHP_CURL_HTTP_REMOTE_SERVER');
}
- $php_executable = getenv('TEST_PHP_EXECUTABLE');
- $doc_root = __DIR__;
- $router = "responder/get.php";
-
- $descriptorspec = array(
- 0 => STDIN,
- 1 => STDOUT,
- 2 => STDERR,
- );
-
- if (substr(PHP_OS, 0, 3) == 'WIN') {
- $cmd = "{$php_executable} -t {$doc_root} -n -S " . PHP_CURL_SERVER_ADDRESS;
+ $php_executable = getenv('TEST_PHP_EXECUTABLE');
+ $doc_root = __DIR__;
+ $router = "responder/get.php";
+
+ $descriptorspec = array(
+ 0 => STDIN,
+ 1 => STDOUT,
+ 2 => STDERR,
+ );
+
+ if (substr(PHP_OS, 0, 3) == 'WIN') {
+ $cmd = "{$php_executable} -t {$doc_root} -n -S " . PHP_CURL_SERVER_ADDRESS;
+ $cmd .= " {$router}";
+ $handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true, "suppress_errors" => true));
+ } else {
+ $cmd = "exec {$php_executable} -t {$doc_root} -n -S " . PHP_CURL_SERVER_ADDRESS;
$cmd .= " {$router}";
- $handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true, "suppress_errors" => true));
- } else {
- $cmd = "exec {$php_executable} -t {$doc_root} -n -S " . PHP_CURL_SERVER_ADDRESS;
- $cmd .= " {$router}";
- $cmd .= " 2>/dev/null";
-
- $handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root);
- }
+ $cmd .= " 2>/dev/null";
+
+ $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_CURL_SERVER_HOSTNAME, PHP_CURL_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_CURL_SERVER_HOSTNAME, PHP_CURL_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);
- },
- $handle
+ if ($error) {
+ echo $error;
+ proc_close($handle);
+ exit(1);
+ }
+
+ register_shutdown_function(
+ function($handle) use($router) {
+ proc_terminate($handle);
+ },
+ $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.
+
return PHP_CURL_SERVER_ADDRESS;
}
+