|
| 1 | +--TEST-- |
| 2 | +FPM: GH-8885 - access.log with stderr begins to write logs to error_log after daemon reload |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +include "skipif.inc"; |
| 6 | +FPM\Tester::skipIfRoot(); |
| 7 | +?> |
| 8 | +--FILE-- |
| 9 | +<?php |
| 10 | + |
| 11 | +require_once "tester.inc"; |
| 12 | + |
| 13 | +$cfg = <<<EOT |
| 14 | +[global] |
| 15 | +error_log = {{FILE:LOG}} |
| 16 | +pid = {{FILE:PID}} |
| 17 | +[unconfined] |
| 18 | +listen = {{ADDR}} |
| 19 | +access.log=/dev/stderr |
| 20 | +ping.path = /ping |
| 21 | +ping.response = pong |
| 22 | +pm = dynamic |
| 23 | +pm.max_children = 5 |
| 24 | +pm.start_servers = 1 |
| 25 | +pm.min_spare_servers = 1 |
| 26 | +pm.max_spare_servers = 3 |
| 27 | +EOT; |
| 28 | + |
| 29 | +// php-fpm must not be launched with --force-stderr option |
| 30 | +$tester = new FPM\Tester($cfg, '', [FPM\Tester::PHP_FPM_DISABLE_FORCE_STDERR => true]); |
| 31 | +// getPrefixedFile('err.log') is the same path that returns processTemplate('{{FILE:LOG}}') |
| 32 | +$errorLogFile = $tester->getPrefixedFile('err.log'); |
| 33 | + |
| 34 | +$tester->start(); |
| 35 | +$tester->expectNoLogMessages(); |
| 36 | + |
| 37 | +$content = file_get_contents($errorLogFile); |
| 38 | +assert($content !== false && strlen($content) > 0, 'File must not be empty'); |
| 39 | + |
| 40 | +$errorLogLines = explode("\n", $content); |
| 41 | +array_pop($errorLogLines); |
| 42 | + |
| 43 | +assert(count($errorLogLines) === 2, 'Expected 2 records in the error_log file'); |
| 44 | +assert(strpos($errorLogLines[0], 'NOTICE: fpm is running, pid')); |
| 45 | +assert(strpos($errorLogLines[1], 'NOTICE: ready to handle connections')); |
| 46 | + |
| 47 | +$tester->ping('{{ADDR}}'); |
| 48 | +$stderrLines = $tester->getLogLines(-1); |
| 49 | +assert(count($stderrLines) === 1, 'Expected 1 record in the stderr output (access.log)'); |
| 50 | +$stderrLine = $stderrLines[0]; |
| 51 | +assert(preg_match('/127.0.0.1 .* "GET \/ping" 200$/', $stderrLine), 'Incorrect format of access.log record'); |
| 52 | + |
| 53 | +$tester->signal('USR2'); |
| 54 | +$tester->expectLogNotice('using inherited socket fd=\d+, "127.0.0.1:\d+"'); |
| 55 | + |
| 56 | +$content = file_get_contents($errorLogFile); |
| 57 | +assert($content !== false && strlen($content) > 0, 'File must not be empty'); |
| 58 | +$errorLogLines = explode("\n", $content); |
| 59 | +array_pop($errorLogLines); |
| 60 | + |
| 61 | +assert(count($errorLogLines) >= 5, 'Expected at least 5 records in the error_log file'); |
| 62 | +assert(strpos($errorLogLines[0], 'NOTICE: fpm is running, pid')); |
| 63 | +assert(strpos($errorLogLines[1], 'NOTICE: ready to handle connections')); |
| 64 | +assert(strpos($errorLogLines[2], 'NOTICE: Reloading in progress')); |
| 65 | +assert(strpos($errorLogLines[3], 'NOTICE: reloading: execvp')); |
| 66 | +assert(strpos($errorLogLines[4], 'NOTICE: using inherited socket')); |
| 67 | + |
| 68 | +$tester->ping('{{ADDR}}'); |
| 69 | +$stderrLines = $tester->getLogLines(-1); |
| 70 | +assert(count($stderrLines) === 1, 'Must be only 1 record in the access.log'); |
| 71 | +assert(preg_match('/127.0.0.1 .* "GET \/ping" 200$/', $stderrLines[0]), 'Incorrect format of access.log record'); |
| 72 | + |
| 73 | +$tester->terminate(); |
| 74 | +$stderrLines = $tester->expectNoLogMessages(); |
| 75 | + |
| 76 | +$content = file_get_contents($errorLogFile); |
| 77 | +assert($content !== false && strlen($content) > 0, 'File must not be empty'); |
| 78 | +$errorLogLines = explode("\n", $content); |
| 79 | +array_pop($errorLogLines); |
| 80 | +$errorLogLastLine = array_pop($errorLogLines); |
| 81 | +assert(strpos($errorLogLastLine, 'NOTICE: exiting, bye-bye')); |
| 82 | + |
| 83 | +$tester->close(); |
| 84 | +?> |
| 85 | +Done |
| 86 | +--EXPECT-- |
| 87 | +Done |
| 88 | +--CLEAN-- |
| 89 | +<?php |
| 90 | +require_once "tester.inc"; |
| 91 | +FPM\Tester::clean(); |
| 92 | +?> |
0 commit comments