Files
XC_VM/tests/Unit/TestDbSharedSchemaTest.php
T
obscuremind 4e19204712 test(support): let several processes share one TestDb schema
XC_VM_Fanout's interop harness runs MAIN's PHP as many processes over
one database. Since the unit suite moved to MariaDB, every TestDb opened
a throwaway schema of its own and dropped it with the instance, so the
harness could not share MAIN's state and every panel-backed agent test
failed at its setup.

new TestDb('xcvm_t<pid>_<n>') opens that schema, creating it when
missing, and no instance drops it. Named after a process that outlives
the others (the Go test), TestDb's orphan cleanup drops it once that
process has ended. ADR 0004's note on the interop test says it runs
again.
2026-10-07 21:38:57 +00:00

30 lines
1.0 KiB
PHP

<?php
use PHPUnit\Framework\TestCase;
/**
* TestDb's shared schema: one database several processes use (XC_VM_Fanout's
* interop harness), which no instance drops.
*/
final class TestDbSharedSchemaTest extends TestCase {
public function testInstancesShareTheSchemaAndNoneDropsIt(): void {
$rName = 'xcvm_t' . getmypid() . '_9' . random_int(100000, 999999);
$rFirst = new TestDb($rName);
try {
$rFirst->exec('CREATE TABLE `kept` (`id` int)');
$rFirst->exec('INSERT INTO `kept` VALUES (7)');
$rSecond = new TestDb($rName);
$this->assertSame(7, (int) $rSecond->pdo->query('SELECT `id` FROM `kept`')->fetchColumn(), 'the other instance sees it');
unset($rSecond);
$this->assertSame(7, (int) $rFirst->pdo->query('SELECT `id` FROM `kept`')->fetchColumn(), 'an instance gone leaves the schema');
} finally {
$rFirst->pdo->exec('DROP DATABASE IF EXISTS `' . $rName . '`');
}
}
public function testOnlyAnOrphanCleanupNameIsTaken(): void {
$this->expectException(InvalidArgumentException::class);
new TestDb('interop');
}
}