Files
XC_VM/tests/Unit/SignalsLoopQueryRateTest.php
T
Divarion_D 9e118da975 test: run the unit suite on MariaDB only, and on the panel's own stack
The suite ran on in-memory SQLite, an engine production never uses: it hid
column lengths, MySQL-only syntax and type coercion (the identity bug fixed in
the previous commit passed CI that way). SQLite is gone:

- TestDb connects only to MariaDB/MySQL (XCVM_TEST_DB_DSN/_USER/_PASS; root over
  the local socket, else 127.0.0.1:3306). Each instance gets a throwaway
  schema, dropped with it, in the installer's sql_mode, with an explicit
  connect timeout (a boot under test can zero default_socket_timeout).
- InstallSchema and the tests take the production DDL as is: the SQLite
  reducers, the keys they re-added, the faked information_schema and the
  sqliteCreateFunction() stand-ins are removed; test DDL is MySQL DDL.
- ReplicaBootTest, DbConnectRefusalTest and LazyDatabaseHandlerTest reach the
  test server instead of SQLite files; RecordingFinalizer no longer swallows
  an information_schema failure "for tests on SQLite".
- `make test-db` starts a throwaway mariadb:11.4 (tmpfs) for a machine without
  a server; the CI PHPUnit job gets the same as a service.

The suite also runs on a panel host with the bundled PHP and its own php.ini:
tests reach the code through MAIN_HOME, not `<repo>/src`; repository checks
and process-isolated tests (ionCube Loader + OPcache CLI segfault on a script
read from stdin) are in the skip-on-panel group; xcvm_test_child_php() starts
a child that fakes \XC_VM without the real extension; Redis-down tests use
RedisManager::useConnector() instead of an eval'd \XC_VM.

Stale opt-in tests fixed on the way: the real-agent provisioning test answers
the agent-started check, the extension integration test sends the typed starts
and reads the binary signature raw, a fake producer starts as PHP_BINARY, and
the certbot test waits for the line its background command writes.
2026-10-04 16:12:23 +03:00

62 lines
1.9 KiB
PHP

<?php
use PHPUnit\Framework\TestCase;
use XcVm\Cli\DaemonTrait;
/**
* The signals daemon re-read `servers` (a SELECT * against MAIN) on every
* pass of its loop once it had run a settings check — four times a second on
* every node. Persistent loops now reload the servers list on a five-second
* timer shared through DaemonTrait.
*/
final class SignalsLoopQueryRateTest extends TestCase {
private function daemon(): object {
return new class {
use DaemonTrait;
public function due(?int $rNow): bool {
return $this->serversRefreshDue($rNow);
}
public function markRefreshed(int $rAt): void {
$this->rServersRefreshedAt = $rAt;
}
};
}
public function testReloadAtMostEveryFiveSeconds(): void {
$rDaemon = $this->daemon();
$this->assertTrue($rDaemon->due(1000), 'first pass loads');
$rDaemon->markRefreshed(1000);
$this->assertFalse($rDaemon->due(1000));
$this->assertFalse($rDaemon->due(1004));
$this->assertTrue($rDaemon->due(1005));
}
public function testAQuarterSecondLoopReadsServersTwelveTimesAMinuteNotTwoHundredForty(): void {
$rDaemon = $this->daemon();
$rReads = 0;
for ($rTick = 0; $rTick < 240; $rTick++) { // one minute at usleep(250000)
$rNow = 1000 + intdiv($rTick, 4);
if ($rDaemon->due($rNow)) {
$rReads++;
$rDaemon->markRefreshed($rNow);
}
}
$this->assertSame(12, $rReads);
}
/** @dataProvider daemons */
public function testDaemonsUseTheTimer(string $rFile): void {
$rSource = (string) file_get_contents(MAIN_HOME . 'Cli/Commands/' . $rFile);
$this->assertStringContainsString('$this->serversRefreshDue()', $rSource);
$this->assertStringNotContainsString('ServerRepository::getAll(true)', $rSource);
}
/** @return array<string, array{string}> */
public static function daemons(): array {
return ['signals' => ['SignalsCommand.php'], 'watchdog' => ['WatchdogCommand.php'], 'cache handler' => ['CacheHandlerCommand.php']];
}
}