Skip to content

Commit 6f1670c

Browse files
committed
Stage-by-stage reproduction of test setUp() to isolate segfault
1 parent 2555d7c commit 6f1670c

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

.github/workflows/phpunit-tests-turso.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,64 @@ jobs:
123123
ignore-cache: "yes"
124124
composer-options: "--optimize-autoloader"
125125

126+
- name: Staged reproduction of test setUp()
127+
continue-on-error: true
128+
env:
129+
LD_PRELOAD: ${{ steps.turso-lib.outputs.path }}
130+
working-directory: packages/mysql-on-sqlite
131+
run: |
132+
php -d 'output_buffering=0' <<'PHP'
133+
<?php
134+
require __DIR__ . '/tests/bootstrap.php';
135+
echo "[1] bootstrap ok\n";
136+
137+
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
138+
$pdo = new $pdo_class('sqlite::memory:');
139+
echo "[2] PDO({$pdo_class}) ok\n";
140+
141+
$pdo->exec('PRAGMA foreign_keys = ON');
142+
echo "[3] PRAGMA foreign_keys ok\n";
143+
144+
// Same as WP_SQLite_PDO_User_Defined_Functions::register_for but with
145+
// a running count so we see how far we got before any crash.
146+
$funcs = new WP_SQLite_PDO_User_Defined_Functions();
147+
$ref = new ReflectionClass($funcs);
148+
$prop = $ref->getProperty('functions');
149+
$prop->setAccessible(true);
150+
$list = $prop->getValue($funcs);
151+
echo "[4] UDF list: " . count($list) . " entries\n";
152+
153+
$n = 0;
154+
foreach ($list as $name => $method) {
155+
$n++;
156+
if ($pdo instanceof PDO\SQLite) {
157+
$pdo->createFunction($name, [$funcs, $method]);
158+
} else {
159+
$pdo->sqliteCreateFunction($name, [$funcs, $method]);
160+
}
161+
echo "[5.{$n}] registered {$name}\n";
162+
}
163+
echo "[6] all UDFs registered\n";
164+
165+
// Register a tiny extra query to see if calling a registered UDF from SQL works.
166+
$row = $pdo->query("SELECT md5('x') AS v")->fetch(PDO::FETCH_ASSOC);
167+
echo "[7] md5('x') -> " . json_encode($row) . "\n";
168+
169+
// Now build the full driver.
170+
$conn = new WP_SQLite_Connection(['pdo' => $pdo]);
171+
echo "[8] Connection ok\n";
172+
173+
$engine = new WP_SQLite_Driver($conn, 'wp');
174+
echo "[9] Driver ok\n";
175+
176+
$engine->query("CREATE TABLE _options (
177+
ID INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
178+
option_name TEXT NOT NULL default '',
179+
option_value TEXT NOT NULL default ''
180+
);");
181+
echo "[10] CREATE TABLE _options ok\n";
182+
PHP
183+
126184
- name: Run PHPUnit tests against Turso DB
127185
continue-on-error: true
128186
env:

0 commit comments

Comments
 (0)