Fix GH-16932: wrong FPM status output

Closes GH-16974

Co-authored-by: James Lucas <james@lucas.net.au>
This commit is contained in:
Jakub Zelenka 2024-11-27 22:56:55 +01:00
parent 3c70f5e976
commit d165670d04
No known key found for this signature in database
GPG key ID: 1C0779DC5C0A9DE4
3 changed files with 81 additions and 2 deletions

View file

@ -201,7 +201,7 @@ void fpm_request_end(void)
fpm_scoreboard_proc_release(proc);
/* memory_peak */
fpm_scoreboard_update_commit(0, 0, 0, 0, 0, 0, 0, proc->memory, FPM_SCOREBOARD_ACTION_SET, NULL);
fpm_scoreboard_update_commit(-1, -1, -1, -1, -1, -1, -1, proc->memory, FPM_SCOREBOARD_ACTION_SET, NULL);
}
void fpm_request_finished(void)

View file

@ -0,0 +1,56 @@
--TEST--
FPM: GH-16932 - scoreboard fields are reset after the request
--EXTENSIONS--
pcntl
--SKIPIF--
<?php
include "skipif.inc";
?>
--FILE--
<?php
require_once "tester.inc";
$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
pid = {{FILE:PID}}
[unconfined]
listen = {{ADDR}}
pm.status_path = /status
pm = dynamic
pm.max_children = 2
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
EOT;
$code = <<<EOT
<?php
echo "hi!";
EOT;
$tester = new FPM\Tester($cfg, $code);
$tester->start(extensions: ['pcntl']);
$tester->expectLogStartNotices();
$tester->request();
$tester->request();
$tester->request();
$tester->request();
$tester
->request(uri: '/status', query: 'json')
->expectJsonBodyPatternForStatusField('accepted conn', '5');
$tester->terminate();
$tester->expectLogTerminatingNotices();
$tester->close();
?>
Done
--EXPECT--
Done
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>

View file

@ -148,6 +148,29 @@ class Response extends BaseResponse
return $this;
}
/**
* Expect status field with value that matches the supplied pattern.
*
* @param string $fieldName
* @param string $pattern
*
* @return Response
*/
public function expectJsonBodyPatternForStatusField(string $fieldName, string $pattern): Response
{
$rawData = $this->getBody('application/json');
$data = json_decode($rawData, true);
if (preg_match('|' . $pattern . '|', $data[$fieldName]) > 0) {
return $this;
}
$this->error(
"Field $fieldName did not match pattern $pattern in status data '$rawData'"
);
return $this;
}
/**
* Expect that one of the processes in json status process list has a field with value that
* matches the supplied pattern.
@ -167,7 +190,7 @@ class Response extends BaseResponse
);
}
foreach ($data['processes'] as $process) {
if (preg_match('|' . $pattern . '|', $process[$fieldName]) !== false) {
if (preg_match('|' . $pattern . '|', $process[$fieldName]) > 0) {
return $this;
}
}