mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-10-26 11:03:14 +01:00
Review follow-up to the bandwidth/rps/producers fix. The nginx stub_status parse moves into SystemInfo::nginxRequestCount(), so the requests field the watchdog samples is tested against a real status body and an unreachable one (no count, rps 0). The getStats() test now pins the whole array_replace statement (a `+` would leave the bandwidth keys at 0), and the sampler test checks that 120 s is in range by default. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TQHeypQpfAXTdCysmi7b6a
28 lines
1.2 KiB
PHP
28 lines
1.2 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use XcVm\Core\Util\SystemInfo;
|
|
|
|
/**
|
|
* SystemInfo::nginxRequestCount — the counter the watchdog samples for
|
|
* servers.requests_per_second. stub_status reports accepts, handled and
|
|
* requests on its third line; reading the wrong field would feed a connection
|
|
* count into the request rate.
|
|
*/
|
|
final class SystemInfoNginxStatusTest extends TestCase {
|
|
|
|
public function testTheRequestCountIsTheThirdCounter(): void {
|
|
$rStatus = "Active connections: 3 \nserver accepts handled requests\n 10 10 57 \nReading: 0 Writing: 1 Waiting: 2 \n";
|
|
|
|
$this->assertSame(57.0, SystemInfo::nginxRequestCount($rStatus));
|
|
}
|
|
|
|
public function testAnUnreachableOrMalformedStatusHasNoCount(): void {
|
|
// The watchdog passes '' when the status page cannot be fetched.
|
|
$this->assertNull(SystemInfo::nginxRequestCount(''));
|
|
$this->assertNull(SystemInfo::nginxRequestCount("Active connections: 3 \nserver accepts handled requests\n"));
|
|
$this->assertNull(SystemInfo::nginxRequestCount("Active connections: 3 \nserver accepts handled requests\n 10 10 \n"));
|
|
$this->assertNull(SystemInfo::nginxRequestCount("<html>\n<head><title>404 Not Found</title></head>\n<body>x y z</body>\n"));
|
|
}
|
|
}
|