]> granicus.if.org Git - php/commitdiff
Add test for bug #68442
authorRemi Collet <remi@php.net>
Tue, 18 Nov 2014 10:08:49 +0000 (11:08 +0100)
committerRemi Collet <remi@php.net>
Tue, 18 Nov 2014 10:08:49 +0000 (11:08 +0100)
Add another helper function fpm_display_log

Restore change from c996a989 badly reverted in 8c0cc49

sapi/fpm/tests/002.phpt
sapi/fpm/tests/003.phpt
sapi/fpm/tests/012.phpt [new file with mode: 0644]
sapi/fpm/tests/include.inc

index 2ef6cedc3856ac42c03635f66a634d302fa49bc6..ce878661eaf54e8ee66f2fd9fd5d08a2a7d2933a 100644 (file)
@@ -8,12 +8,13 @@ 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:9000
+listen = 127.0.0.1:$port
 pm = dynamic
 pm.max_children = 5
 pm.start_servers = 2
@@ -26,7 +27,7 @@ if (is_resource($fpm)) {
     var_dump(fgets($tail));
     var_dump(fgets($tail));
     $i = 0;
-    while (($i++ < 30) && !($fp = @fsockopen('127.0.0.1', 9000))) {
+    while (($i++ < 30) && !($fp = @fsockopen('127.0.0.1', $port))) {
         usleep(10000);
     }
     if ($fp) {
index 389cb2401ef2de7403c993193ac8451f318ca232..0ce1bd2828ad4560d07c41075fdef644190b623d 100644 (file)
@@ -8,12 +8,13 @@ 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]:9000
+listen = [::1]:$port
 pm = dynamic
 pm.max_children = 5
 pm.start_servers = 2
@@ -26,7 +27,7 @@ if (is_resource($fpm)) {
     var_dump(fgets($tail));
     var_dump(fgets($tail));
     $i = 0;
-    while (($i++ < 30) && !($fp = fsockopen('[::1]', 9000))) {
+    while (($i++ < 30) && !($fp = fsockopen('[::1]', $port))) {
         usleep(10000);
     }
     if ($fp) {
diff --git a/sapi/fpm/tests/012.phpt b/sapi/fpm/tests/012.phpt
new file mode 100644 (file)
index 0000000..d96c530
--- /dev/null
@@ -0,0 +1,79 @@
+--TEST--
+FPM: Test reload configuration (bug #68442)
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--FILE--
+<?php
+
+include "include.inc";
+
+$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
+$pidfile = dirname(__FILE__).'/php-fpm.pid';
+$port = 9000+PHP_INT_SIZE;
+
+$cfg = <<<EOT
+[global]
+error_log = $logfile
+pid = $pidfile
+[unconfined]
+listen = 127.0.0.1:$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)) {
+    fpm_display_log($tail, 2);
+    try {
+               var_dump(strpos(run_request('127.0.0.1', $port), 'pong'));
+               echo "IPv4 ok\n";
+       } catch (Exception $e) {
+               echo "IPv4 error\n";
+       }
+
+       $pid=file_get_contents($pidfile);
+       if ($pid) {
+               exec("kill -USR2 $pid");
+       } else {
+               die("PID not found\n");
+       }
+    fpm_display_log($tail, 5);
+
+    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
+[%d-%s-%d %d:%d:%d] NOTICE: Reloading in progress ...
+[%d-%s-%d %d:%d:%d] NOTICE: reloading: %s
+[%d-%s-%d %d:%d:%d] NOTICE: using inherited socket fd=%d, "127.0.0.1:%d"
+[%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);
+       $pidfile = dirname(__FILE__).'/php-fpm.pid';
+    @unlink($pidfile);
+?>
index 5d01ae693dab48e08c52a6ba321f65176c2135f0..b195fad507325709d389218733da07a55ef38179 100644 (file)
@@ -76,6 +76,16 @@ function run_fpm_till($needle, $config, $max = 10) /* {{{ */
 }
 /* }}} */
 
+function fpm_display_log($tail, $n=1, $ignore='systemd') {
+       while ($n) {
+               $a = fgets($tail);
+               if (empty($ignore) || !strpos($a, $ignore)) {
+                       echo $a;
+                       $n--;
+               }
+       }
+}
+
 function run_request($host, $port, $uri='/ping', $query='') {
        require_once 'fcgi.inc';
        $client = new Adoy\FastCGI\Client($host, $port);