mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-11-06 03:03:25 +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.
73 lines
2.7 KiB
PHP
73 lines
2.7 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use XcVm\Domain\Stream\StreamStateWriter;
|
|
|
|
/**
|
|
* A node's runtime state for a stream (pids, status, probe results, progress)
|
|
* is written through StreamStateWriter; desired state stays MAIN's. The SQL
|
|
* sink writes the same UPDATE the ~30 call sites wrote, and any column
|
|
* outside the runtime-state list is refused.
|
|
*/
|
|
final class StreamStateWriterTest extends TestCase {
|
|
|
|
private function recorder(): object {
|
|
return new class {
|
|
/** @var list<array{string, list<mixed>}> */
|
|
public array $rQueries = [];
|
|
public function query(string $rSql, mixed ...$rParams): bool {
|
|
$this->rQueries[] = [$rSql, $rParams];
|
|
return true;
|
|
}
|
|
};
|
|
}
|
|
|
|
protected function tearDown(): void {
|
|
StreamStateWriter::useSink(null);
|
|
}
|
|
|
|
public function testUpdateByStreamAndServer(): void {
|
|
$rDb = $this->recorder();
|
|
StreamStateWriter::update(12, 3, ['pid' => 4242, 'stream_status' => 0, 'stream_info' => null], $rDb);
|
|
$this->assertSame([[
|
|
'UPDATE `streams_servers` SET `pid` = ?, `stream_status` = ?, `stream_info` = ? WHERE `stream_id` = ? AND `server_id` = ?',
|
|
[4242, 0, null, 12, 3],
|
|
]], $rDb->rQueries);
|
|
}
|
|
|
|
public function testUpdateByRowId(): void {
|
|
$rDb = $this->recorder();
|
|
StreamStateWriter::updateRow(77, ['progress_info' => ''], $rDb);
|
|
$this->assertSame([['UPDATE `streams_servers` SET `progress_info` = ? WHERE `server_stream_id` = ?', ['', 77]]], $rDb->rQueries);
|
|
StreamStateWriter::updateRow(77, [], $rDb);
|
|
$this->assertCount(1, $rDb->rQueries, 'nothing to write, no query');
|
|
}
|
|
|
|
public function testDesiredStateColumnsAreRefused(): void {
|
|
$this->expectException(InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('parent_id');
|
|
StreamStateWriter::update(1, 1, ['pid' => 1, 'parent_id' => 5], $this->recorder());
|
|
}
|
|
|
|
public function testSinkReceivesTheIntent(): void {
|
|
$rSeen = [];
|
|
StreamStateWriter::useSink(function (string $rWhere, array $rFields, array $rKeys) use (&$rSeen): bool {
|
|
$rSeen[] = [$rWhere, $rFields, $rKeys];
|
|
return true;
|
|
});
|
|
StreamStateWriter::update(5, 2, ['monitor_pid' => 9]);
|
|
$this->assertSame([['`stream_id` = ? AND `server_id` = ?', ['monitor_pid' => 9], [5, 2]]], $rSeen);
|
|
}
|
|
|
|
public function testRuntimeWritersUseTheSeam(): void {
|
|
$rRoot = MAIN_HOME;
|
|
foreach ([
|
|
'Domain/Stream/StreamProcess.php', 'Cli/Commands/MonitorCommand.php', 'Cli/CronJobs/StreamsCronJob.php',
|
|
'Cli/CronJobs/VodCronJob.php', 'Cli/CronJobs/CleanupCronJob.php', 'Cli/Commands/CreatedCommand.php',
|
|
'Cli/Commands/DelayCommand.php', 'Cli/Commands/ScannerCommand.php',
|
|
] as $rFile) {
|
|
$this->assertStringNotContainsString('UPDATE `streams_servers` SET', (string) file_get_contents($rRoot . $rFile), $rFile);
|
|
}
|
|
}
|
|
}
|