Skip to content

Commit 9aa31fd

Browse files
committed
Run SQLite tests with native parser extension in CI
1 parent 4c7f5a4 commit 9aa31fd

2 files changed

Lines changed: 84 additions & 8 deletions

File tree

.github/workflows/mysql-parser-extension-tests.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ on:
55
paths:
66
- '.github/workflows/mysql-parser-extension-tests.yml'
77
- 'packages/mysql-on-sqlite/**'
8+
- 'tmp-test-native/**'
89
pull_request:
910
paths:
1011
- '.github/workflows/mysql-parser-extension-tests.yml'
1112
- 'packages/mysql-on-sqlite/**'
13+
- 'tmp-test-native/**'
1214
workflow_dispatch:
1315

1416
concurrency:
@@ -67,3 +69,76 @@ jobs:
6769
- name: Run PHPUnit tests with parser extension
6870
run: php -d extension="$GITHUB_WORKSPACE/packages/mysql-on-sqlite/ext/wp-mysql-parser/target/debug/libwp_mysql_parser.so" ./vendor/bin/phpunit -c ./phpunit.xml.dist
6971
working-directory: packages/mysql-on-sqlite
72+
73+
sqlite-driver-extension-tests:
74+
name: PHP 8.2 / SQLite driver / Rust extension / ubuntu-latest
75+
runs-on: ubuntu-latest
76+
timeout-minutes: 20
77+
78+
steps:
79+
- name: Checkout repository
80+
uses: actions/checkout@v4
81+
82+
- name: Set up PHP
83+
uses: shivammathur/setup-php@v2
84+
with:
85+
php-version: '8.2'
86+
coverage: none
87+
tools: phpunit-polyfills
88+
89+
- name: Set up Rust
90+
uses: dtolnay/rust-toolchain@stable
91+
92+
- name: Install native build dependencies
93+
run: |
94+
sudo apt-get update
95+
sudo apt-get install -y libclang-dev
96+
echo "PHP_CONFIG=$(command -v php-config)" >> "$GITHUB_ENV"
97+
LIBCLANG_SO="$(find /usr/lib -name 'libclang.so*' | head -n 1)"
98+
echo "LIBCLANG_PATH=$(dirname "$LIBCLANG_SO")" >> "$GITHUB_ENV"
99+
100+
- name: Install Composer dependencies (root)
101+
uses: ramsey/composer-install@v3
102+
with:
103+
ignore-cache: "yes"
104+
composer-options: "--optimize-autoloader"
105+
106+
- name: Install Composer dependencies (mysql-on-sqlite)
107+
uses: ramsey/composer-install@v3
108+
with:
109+
working-directory: packages/mysql-on-sqlite
110+
ignore-cache: "yes"
111+
composer-options: "--optimize-autoloader"
112+
113+
- name: Build parser extension
114+
run: cargo build
115+
working-directory: packages/mysql-on-sqlite/ext/wp-mysql-parser
116+
117+
- name: Verify SQLite driver selects the native parser path
118+
run: |
119+
php -d extension="$GITHUB_WORKSPACE/packages/mysql-on-sqlite/ext/wp-mysql-parser/target/debug/libwp_mysql_parser.so" -r '
120+
require "packages/mysql-on-sqlite/src/load.php";
121+
$lexer = new WP_MySQL_Lexer( "SELECT 1" );
122+
if ( ! method_exists( $lexer, "native_token_stream" ) ) {
123+
fwrite( STDERR, "Native token stream is not available.\n" );
124+
exit( 1 );
125+
}
126+
$driver = new WP_PDO_MySQL_On_SQLite( "mysql-on-sqlite:path=:memory:;dbname=wp;" );
127+
$parser = $driver->create_parser( "SELECT 1" );
128+
$parser->next_query();
129+
$ast = $parser->get_query_ast();
130+
$property = ( new ReflectionClass( $ast ) )->getProperty( "native_ast" );
131+
$property->setAccessible( true );
132+
$native_ast = $property->getValue( $ast );
133+
if ( ! is_object( $native_ast ) || "WP_MySQL_Native_Ast" !== get_class( $native_ast ) ) {
134+
fwrite( STDERR, "SQLite driver did not return a native-backed AST.\n" );
135+
exit( 1 );
136+
}
137+
'
138+
139+
- name: Run PHPUnit tests with SQLite driver using parser extension
140+
run: php -d extension="$GITHUB_WORKSPACE/packages/mysql-on-sqlite/ext/wp-mysql-parser/target/debug/libwp_mysql_parser.so" ./vendor/bin/phpunit -c ./phpunit.xml.dist
141+
working-directory: packages/mysql-on-sqlite
142+
143+
- name: Run native SQLite facade smoke workload
144+
run: php -d extension="$GITHUB_WORKSPACE/packages/mysql-on-sqlite/ext/wp-mysql-parser/target/debug/libwp_mysql_parser.so" tmp-test-native/run-sqlite-facade-smoke.php

tmp-test-native/run-sqlite-facade-smoke.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ function smoke_fail( string $message ): void {
1515

1616
function create_driver(): WP_PDO_MySQL_On_SQLite {
1717
$db = new WP_PDO_MySQL_On_SQLite( 'mysql-on-sqlite:path=:memory:;dbname=wp;' );
18-
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
19-
$db->setAttribute( PDO::ATTR_STRINGIFY_FETCHES, true );
18+
$db->setAttribute( constant( 'PDO::ATTR_ERRMODE' ), constant( 'PDO::ERRMODE_EXCEPTION' ) );
19+
$db->setAttribute( constant( 'PDO::ATTR_STRINGIFY_FETCHES' ), true );
2020
return $db;
2121
}
2222

2323
function seed_database( WP_PDO_MySQL_On_SQLite $db ): void {
2424
$db->query(
25-
'CREATE TABLE `' . TEST_TABLE . "` (
25+
'CREATE TABLE `' . TEST_TABLE . '` (
2626
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
2727
`tenant_id` int NOT NULL,
2828
`label` varchar(191) NOT NULL,
@@ -31,7 +31,7 @@ function seed_database( WP_PDO_MySQL_On_SQLite $db ): void {
3131
PRIMARY KEY (`id`),
3232
KEY `tenant_score` (`tenant_id`, `score`),
3333
KEY `label_score` (`label`, `score`)
34-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
34+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4'
3535
);
3636

3737
for ( $i = 1; $i <= 64; $i++ ) {
@@ -136,18 +136,19 @@ function parse_with_sqlite_driver( WP_PDO_MySQL_On_SQLite $db, string $sql ): in
136136

137137
function execute_with_sqlite_driver( WP_PDO_MySQL_On_SQLite $db, string $sql ): int {
138138
$result = $db->query( $sql );
139-
if ( ! $result instanceof PDOStatement ) {
139+
if ( ! is_object( $result ) || ! method_exists( $result, 'fetchAll' ) ) {
140140
return 0;
141141
}
142142

143-
return count( $result->fetchAll( PDO::FETCH_ASSOC ) );
143+
return count( $result->fetchAll( constant( 'PDO::FETCH_ASSOC' ) ) );
144144
}
145145

146146
function run_workload(): void {
147147
require_once dirname( __DIR__ ) . '/packages/mysql-on-sqlite/src/load.php';
148148

149-
$query_count = (int) ( getenv( 'TMP_TEST_NATIVE_QUERY_COUNT' ) ?: DEFAULT_QUERY_COUNT );
150-
$db = create_driver();
149+
$query_count_env = getenv( 'TMP_TEST_NATIVE_QUERY_COUNT' );
150+
$query_count = (int) ( false === $query_count_env ? DEFAULT_QUERY_COUNT : $query_count_env );
151+
$db = create_driver();
151152
seed_database( $db );
152153

153154
$start = microtime( true );

0 commit comments

Comments
 (0)