mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-11-02 03:03:39 +01:00
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.
58 lines
2.0 KiB
PHP
58 lines
2.0 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* A daemon's loop must not end in an unconditional `break`.
|
|
*
|
|
* Four of them did (`queue`, `scanner`, `signals`, `watchdog`): the whole pass
|
|
* sat in a `while` whose last statement was `break`, so every pass fell out of
|
|
* the loop and `restartDaemon()` re-executed `console.php` — a fresh bootstrap,
|
|
* settings read and database connect per pass, per node, four times a second in
|
|
* the signals daemon's case. The plan's 24 h RSS and queries/s acceptance
|
|
* cannot be measured on a process that never lives that long.
|
|
*
|
|
* A `break` inside an `if` is how a daemon is meant to stop (a code change, an
|
|
* nginx restart, a dead database): only the unconditional one at the end of the
|
|
* body is refused.
|
|
*/
|
|
final class DaemonLoopTest extends TestCase {
|
|
|
|
public function testNoDaemonLoopEndsWithAnUnconditionalBreak(): void {
|
|
$rChecked = 0;
|
|
|
|
foreach (glob(MAIN_HOME . 'Cli/Commands/*Command.php') ?: [] as $rFile) {
|
|
$rLines = file($rFile) ?: [];
|
|
if (!str_contains(implode('', $rLines), 'restartDaemon(')) {
|
|
continue;
|
|
}
|
|
foreach ($rLines as $rNo => $rLine) {
|
|
if (!preg_match('/^(\t+)(?:\} )?while \(/', $rLine, $rM)) {
|
|
continue;
|
|
}
|
|
$rChecked++;
|
|
$rEnd = self::closes($rLines, $rNo, strlen($rM[1]));
|
|
$rLast = $rEnd === null ? '' : trim($rLines[$rEnd - 1]);
|
|
$this->assertNotSame(
|
|
'break;',
|
|
$rLast,
|
|
basename($rFile) . ':' . $rEnd . ": the loop's last statement is an unconditional break, so the daemon re-executes itself every pass"
|
|
);
|
|
}
|
|
}
|
|
|
|
$this->assertGreaterThan(4, $rChecked, 'the daemon loops were not found at all');
|
|
}
|
|
|
|
/** The line (0-based) of the `}` that closes a block opened at $rNo, indented with $rTabs tabs. */
|
|
private static function closes(array $rLines, int $rNo, int $rTabs): ?int {
|
|
$rClose = str_repeat("\t", $rTabs) . '}';
|
|
for ($i = $rNo + 1; $i < count($rLines); $i++) {
|
|
if (str_starts_with($rLines[$i], $rClose)) {
|
|
return $i;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|