1
0
mirror of https://github.com/php/php-src.git synced 2026-03-25 00:32:23 +01:00

Add various tests for FPM

- covering recent bugs (68420, 68421, 68423, 68428)
- for UDS
- for ping and status URI
- for multi pool and multi mode
This commit is contained in:
Remi Collet
2014-11-18 08:07:45 +01:00
parent a740f9e783
commit 8c0cc49b9b
9 changed files with 467 additions and 6 deletions

View File

@@ -8,13 +8,12 @@ FPM: Startup and connect
include "include.inc";
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
$port = 9000+PHP_INT_SIZE;
$cfg = <<<EOT
[global]
error_log = $logfile
[unconfined]
listen = 127.0.0.1:$port
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
@@ -27,7 +26,7 @@ if (is_resource($fpm)) {
var_dump(fgets($tail));
var_dump(fgets($tail));
$i = 0;
while (($i++ < 30) && !($fp = @fsockopen('127.0.0.1', $port))) {
while (($i++ < 30) && !($fp = @fsockopen('127.0.0.1', 9000))) {
usleep(10000);
}
if ($fp) {

View File

@@ -8,13 +8,12 @@ FPM: Test IPv6 support
include "include.inc";
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
$port = 9000+PHP_INT_SIZE;
$cfg = <<<EOT
[global]
error_log = $logfile
[unconfined]
listen = [::1]:$port
listen = [::1]:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
@@ -27,7 +26,7 @@ if (is_resource($fpm)) {
var_dump(fgets($tail));
var_dump(fgets($tail));
$i = 0;
while (($i++ < 30) && !($fp = fsockopen('[::1]', $port))) {
while (($i++ < 30) && !($fp = fsockopen('[::1]', 9000))) {
usleep(10000);
}
if ($fp) {

58
sapi/fpm/tests/005.phpt Normal file
View File

@@ -0,0 +1,58 @@
--TEST--
FPM: Test IPv4 allowed clients
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php
include "include.inc";
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
$port = 9000+PHP_INT_SIZE;
$cfg = <<<EOT
[global]
error_log = $logfile
[unconfined]
listen = [::]:$port
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOT;
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
echo fgets($tail);
echo fgets($tail);
try {
run_request('127.0.0.1', $port);
echo "IPv4 ok\n";
} catch (Exception $e) {
echo "IPv4 error\n";
}
try {
run_request('[::1]', $port);
echo "IPv6 ok\n";
} catch (Exception $e) {
echo "IPv6 error\n";
}
proc_terminate($fpm);
stream_get_contents($tail);
fclose($tail);
proc_close($fpm);
}
?>
--EXPECTF--
[%d-%s-%d %d:%d:%d] NOTICE: fpm is running, pid %d
[%d-%s-%d %d:%d:%d] NOTICE: ready to handle connections
IPv4 ok
IPv6 error
--CLEAN--
<?php
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
@unlink($logfile);
?>

58
sapi/fpm/tests/006.phpt Normal file
View File

@@ -0,0 +1,58 @@
--TEST--
FPM: Test IPv6 allowed clients (bug #68428)
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php
include "include.inc";
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
$port = 9000+PHP_INT_SIZE;
$cfg = <<<EOT
[global]
error_log = $logfile
[unconfined]
listen = [::]:$port
listen.allowed_clients = ::1
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOT;
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
echo fgets($tail);
echo fgets($tail);
try {
run_request('127.0.0.1', $port);
echo "IPv4 ok\n";
} catch (Exception $e) {
echo "IPv4 error\n";
}
try {
run_request('[::1]', $port);
echo "IPv6 ok\n";
} catch (Exception $e) {
echo "IPv6 error\n";
}
proc_terminate($fpm);
stream_get_contents($tail);
fclose($tail);
proc_close($fpm);
}
?>
--EXPECTF--
[%d-%s-%d %d:%d:%d] NOTICE: fpm is running, pid %d
[%d-%s-%d %d:%d:%d] NOTICE: ready to handle connections
IPv4 error
IPv6 ok
--CLEAN--
<?php
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
@unlink($logfile);
?>

69
sapi/fpm/tests/007.phpt Normal file
View File

@@ -0,0 +1,69 @@
--TEST--
FPM: Test IPv6 all addresses and access_log (bug #68421)
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php
include "include.inc";
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
$accfile = dirname(__FILE__).'/php-fpm.acc.tmp';
$port = 9000+PHP_INT_SIZE;
$cfg = <<<EOT
[global]
error_log = $logfile
[unconfined]
listen = [::]:$port
access.log = $accfile
ping.path = /ping
ping.response = pong
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOT;
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
echo fgets($tail);
echo fgets($tail);
try {
var_dump(strpos(run_request('127.0.0.1', $port), 'pong'));
echo "IPv4 ok\n";
} catch (Exception $e) {
echo "IPv4 error\n";
}
try {
var_dump(strpos(run_request('[::1]', $port), 'pong'));
echo "IPv6 ok\n";
} catch (Exception $e) {
echo "IPv6 error\n";
}
proc_terminate($fpm);
stream_get_contents($tail);
fclose($tail);
proc_close($fpm);
echo file_get_contents($accfile);
}
?>
--EXPECTF--
[%d-%s-%d %d:%d:%d] NOTICE: fpm is running, pid %d
[%d-%s-%d %d:%d:%d] NOTICE: ready to handle connections
int(%d)
IPv4 ok
int(%d)
IPv6 ok
127.0.0.1 %s "GET /ping" 200
::1 %s "GET /ping" 200
--CLEAN--
<?php
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
@unlink($logfile);
$accfile = dirname(__FILE__).'/php-fpm.acc.tmp';
@unlink($accfile);
?>

85
sapi/fpm/tests/008.phpt Normal file
View File

@@ -0,0 +1,85 @@
--TEST--
FPM: Test multi pool (dynamic + ondemand + static) (bug #68423)
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php
include "include.inc";
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
$port1 = 9000+PHP_INT_SIZE;
$port2 = 9001+PHP_INT_SIZE;
$port3 = 9002+PHP_INT_SIZE;
$cfg = <<<EOT
[global]
error_log = $logfile
[pool_dynamic]
listen = 127.0.0.1:$port1
ping.path = /ping
ping.response = pong-dynamic
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
[poold_ondemand]
listen = 127.0.0.1:$port2
ping.path = /ping
ping.response = pong-on-demand
pm = ondemand
pm.max_children = 2
pm.process_idle_timeout = 10
[pool_static]
listen = 127.0.0.1:$port3
ping.path = /ping
ping.response = pong-static
pm = static
pm.max_children = 2
EOT;
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
echo fgets($tail);
echo fgets($tail);
try {
var_dump(strpos(run_request('127.0.0.1', $port1), 'pong-dynamic'));
echo "Dynamic ok\n";
} catch (Exception $e) {
echo "Dynamic error\n";
}
try {
var_dump(strpos(run_request('127.0.0.1', $port2), 'pong-on-demand'));
echo "OnDemand ok\n";
} catch (Exception $e) {
echo "OnDemand error\n";
}
try {
var_dump(strpos(run_request('127.0.0.1', $port3), 'pong-static'));
echo "Static ok\n";
} catch (Exception $e) {
echo "Static error\n";
}
proc_terminate($fpm);
stream_get_contents($tail);
fclose($tail);
proc_close($fpm);
}
?>
--EXPECTF--
[%d-%s-%d %d:%d:%d] NOTICE: fpm is running, pid %d
[%d-%s-%d %d:%d:%d] NOTICE: ready to handle connections
int(%d)
Dynamic ok
int(%d)
OnDemand ok
int(%d)
Static ok
--CLEAN--
<?php
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
@unlink($logfile);
?>

54
sapi/fpm/tests/009.phpt Normal file
View File

@@ -0,0 +1,54 @@
--TEST--
FPM: Test Unix Domain Socket
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php
include "include.inc";
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
$socket = dirname(__FILE__).'/php-fpm.sock';
$cfg = <<<EOT
[global]
error_log = $logfile
[unconfined]
listen = $socket
ping.path = /ping
ping.response = pong
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOT;
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
echo fgets($tail);
echo fgets($tail);
try {
var_dump(strpos(run_request('unix://'.$socket, -1), 'pong'));
echo "UDS ok\n";
} catch (Exception $e) {
echo "UDS error\n";
}
proc_terminate($fpm);
stream_get_contents($tail);
fclose($tail);
proc_close($fpm);
}
?>
--EXPECTF--
[%d-%s-%d %d:%d:%d] NOTICE: fpm is running, pid %d
[%d-%s-%d %d:%d:%d] NOTICE: ready to handle connections
int(%d)
UDS ok
--CLEAN--
<?php
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
@unlink($logfile);
?>

85
sapi/fpm/tests/010.phpt Normal file
View File

@@ -0,0 +1,85 @@
--TEST--
FPM: Test status page
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php
include "include.inc";
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
$port = 9000+PHP_INT_SIZE;
$cfg = <<<EOT
[global]
error_log = $logfile
[unconfined]
listen = 127.0.0.1:$port
pm.status_path = /status
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOT;
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
echo fgets($tail);
echo fgets($tail);
try {
echo run_request('127.0.0.1', $port, '/status');
$html = run_request('127.0.0.1', $port, '/status', 'html');
var_dump(strpos($html, 'text/html') && strpos($html, 'DOCTYPE') && strpos($html, 'PHP-FPM Status Page'));
$json = run_request('127.0.0.1', $port, '/status', 'json');
var_dump(strpos($json, 'application/json') && strpos($json, '"pool":"unconfined"'));
$xml = run_request('127.0.0.1', $port, '/status', 'xml');
var_dump(strpos($xml, 'text/xml') && strpos($xml, '<?xml'));
echo "IPv4 ok\n";
} catch (Exception $e) {
echo "IPv4 error\n";
}
proc_terminate($fpm);
stream_get_contents($tail);
fclose($tail);
proc_close($fpm);
}
?>
--EXPECTF--
[%d-%s-%d %d:%d:%d] NOTICE: fpm is running, pid %d
[%d-%s-%d %d:%d:%d] NOTICE: ready to handle connections
X-Powered-By: PHP/%s
Expires: %s
Cache-Control: %s
Content-type: text/plain%s
pool: unconfined
process manager: dynamic
start time: %s
start since: %d
accepted conn: 1
listen queue: 0
max listen queue: 0
listen queue len: %d
idle processes: 1
active processes: 1
total processes: 2
max active processes: 1
max children reached: 0
slow requests: 0
bool(true)
bool(true)
bool(true)
IPv4 ok
--CLEAN--
<?php
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
@unlink($logfile);
?>

54
sapi/fpm/tests/011.phpt Normal file
View File

@@ -0,0 +1,54 @@
--TEST--
FPM: Test IPv4 all addresses (bug #68420)
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php
include "include.inc";
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
$port = 9000+PHP_INT_SIZE;
$cfg = <<<EOT
[global]
error_log = $logfile
[unconfined]
listen = $port
ping.path = /ping
ping.response = pong
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOT;
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
echo fgets($tail);
echo fgets($tail);
try {
var_dump(strpos(run_request('127.0.0.1', $port), 'pong'));
echo "IPv4 ok\n";
} catch (Exception $e) {
echo "IPv4 error\n";
}
proc_terminate($fpm);
stream_get_contents($tail);
fclose($tail);
proc_close($fpm);
}
?>
--EXPECTF--
[%d-%s-%d %d:%d:%d] NOTICE: fpm is running, pid %d
[%d-%s-%d %d:%d:%d] NOTICE: ready to handle connections
int(%d)
IPv4 ok
--CLEAN--
<?php
$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
@unlink($logfile);
?>