diff options
author | Anatoliy Belsky <ab@php.net> | 2012-05-06 18:06:12 +0200 |
---|---|---|
committer | Anatoliy Belsky <ab@php.net> | 2012-05-06 18:06:12 +0200 |
commit | 692cc976ca6860400a0538835d5be8249eaf8f60 (patch) | |
tree | 679ac53dfe5d53edfa6fe521b2467f221aa9a023 | |
parent | 067fad1b52e0db5914c1a2ce12e4fecfbe95320c (diff) | |
parent | 87a011d3723aa9500e12a3f982df6b1f5cdfaedd (diff) | |
download | php-git-692cc976ca6860400a0538835d5be8249eaf8f60.tar.gz |
Merge branch 'PHP-5.4'
* PHP-5.4:
Fix bug 61769 Random failure of php_cli_server*phpt tests
-rw-r--r-- | sapi/cli/tests/php_cli_server.inc | 23 | ||||
-rw-r--r-- | sapi/cli/tests/php_cli_server_014.phpt | 4 |
2 files changed, 25 insertions, 2 deletions
diff --git a/sapi/cli/tests/php_cli_server.inc b/sapi/cli/tests/php_cli_server.inc index 44ee76ea7f..d24a679e77 100644 --- a/sapi/cli/tests/php_cli_server.inc +++ b/sapi/cli/tests/php_cli_server.inc @@ -1,5 +1,7 @@ <?php -define ("PHP_CLI_SERVER_ADDRESS", "localhost:8964"); +define ("PHP_CLI_SERVER_HOSTNAME", "localhost"); +define ("PHP_CLI_SERVER_PORT", 8964); +define ("PHP_CLI_SERVER_ADDRESS", PHP_CLI_SERVER_HOSTNAME.":".PHP_CLI_SERVER_PORT); function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE) { $php_executable = getenv('TEST_PHP_EXECUTABLE'); @@ -32,6 +34,19 @@ function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE) $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 + $fp = fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT); + if ($fp) { + // server will report Unexpected EOF error (socket opened, closed without writing + // anything) but that can be ignored + fclose($fp); + } else { + // test will fail to connect if server doesn't start listening/accepting + // in the next few microseconds + } + register_shutdown_function( function($handle) use($router) { @@ -40,7 +55,11 @@ function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE) }, $handle ); - usleep(50000); + // don't bother sleeping, server is already up + //usleep(50000); + // 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. } ?> diff --git a/sapi/cli/tests/php_cli_server_014.phpt b/sapi/cli/tests/php_cli_server_014.phpt index 4b56caa70f..2eca8706bb 100644 --- a/sapi/cli/tests/php_cli_server_014.phpt +++ b/sapi/cli/tests/php_cli_server_014.phpt @@ -13,6 +13,10 @@ list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port)?:80; $output = ''; +// note: select() on Windows (& some other platforms) has historical issues with +// timeouts less than 1000 millis(0.5). it may be better to increase these +// timeouts to 1000 millis(1.0) (fsockopen eventually calls select()). +// see articles like: http://support.microsoft.com/kb/257821 $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); |