Skip to content

Commit

Permalink
Simplify driver adapters test configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelff committed Nov 22, 2023
1 parent 2c867f4 commit d2779e4
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 85 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/query-engine-driver-adapters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,23 @@ jobs:
fail-fast: false
matrix:
adapter:
- name: 'planetscale'
setup_task: 'dev-planetscale-js'
- name: 'pg (napi)'
setup_task: 'dev-pg-postgres13'
setup_task: 'dev-pg-js'
- name: 'neon:ws (napi)'
setup_task: 'dev-neon-ws-postgres13'
setup_task: 'dev-neon-js'
- name: 'libsql (napi)'
setup_task: 'dev-libsql-sqlite'
setup_task: 'dev-libsql-js'
# TODO: uncomment when WASM engine is functional
# - name: 'pg (wasm)'
# setup_task: 'dev-pg-postgres13-wasm'
# setup_task: 'dev-pg-wasm'
# needs_wasm_pack: true
# - name: 'neon:ws (wasm)'
# setup_task: 'dev-neon-ws-postgres13-wasm'
# setup_task: 'dev-neon-wasm'
# needs_wasm_pack: true
# - name: 'libsql (wasm)'
# setup_task: 'dev-libsql-sqlite-wasm'
# setup_task: 'dev-libsql-wasm'
# needs_wasm_pack: true
node_version: ['18']
env:
Expand Down
74 changes: 37 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ start-sqlite:
dev-sqlite:
cp $(CONFIG_PATH)/sqlite $(CONFIG_FILE)

dev-libsql-sqlite: build-qe-napi build-connector-kit-js
cp $(CONFIG_PATH)/libsql-sqlite $(CONFIG_FILE)
dev-libsql-js: build-qe-napi build-connector-kit-js
cp $(CONFIG_PATH)/libsql-js $(CONFIG_FILE)

test-libsql-sqlite: dev-libsql-sqlite test-qe-st
test-libsql-js: dev-libsql-js test-qe-st

test-driver-adapter-libsql: test-libsql-sqlite
test-driver-adapter-libsql: test-libsql-js

dev-libsql-sqlite-wasm: build-qe-wasm build-connector-kit-js
cp $(CONFIG_PATH)/libsql-sqlite-wasm $(CONFIG_FILE)
dev-libsql-wasm: build-qe-wasm build-connector-kit-js
cp $(CONFIG_PATH)/libsql-wasm $(CONFIG_FILE)

test-libsql-sqlite-wasm: dev-libsql-sqlite-wasm test-qe-st
test-driver-adapter-libsql-sqlite-wasm: test-libsql-sqlite-wasm
test-libsql-wasm: dev-libsql-wasm test-qe-st
test-driver-adapter-libsql-wasm: test-libsql-wasm

start-postgres9:
docker compose -f docker-compose.yml up --wait -d --remove-orphans postgres9
Expand Down Expand Up @@ -130,36 +130,36 @@ start-postgres13:
dev-postgres13: start-postgres13
cp $(CONFIG_PATH)/postgres13 $(CONFIG_FILE)

start-pg-postgres13: start-postgres13
start-pg-js: start-postgres13

dev-pg-postgres13: start-pg-postgres13 build-qe-napi build-connector-kit-js
cp $(CONFIG_PATH)/pg-postgres13 $(CONFIG_FILE)
dev-pg-js: start-pg-js build-qe-napi build-connector-kit-js
cp $(CONFIG_PATH)/pg-js $(CONFIG_FILE)

test-pg-postgres13: dev-pg-postgres13 test-qe-st
test-pg-js: dev-pg-js test-qe-st

dev-pg-postgres13-wasm: start-pg-postgres13 build-qe-wasm build-connector-kit-js
cp $(CONFIG_PATH)/pg-postgres13-wasm $(CONFIG_FILE)
dev-pg-wasm: start-pg-js build-qe-wasm build-connector-kit-js
cp $(CONFIG_PATH)/pg-wasm $(CONFIG_FILE)

test-pg-postgres13-wasm: dev-pg-postgres13-wasm test-qe-st
test-pg-wasm: dev-pg-wasm test-qe-st

test-driver-adapter-pg: test-pg-postgres13
test-driver-adapter-pg-wasm: test-pg-postgres13-wasm
test-driver-adapter-pg: test-pg-js
test-driver-adapter-pg-wasm: test-pg-wasm

start-neon-postgres13:
docker compose -f docker-compose.yml up --wait -d --remove-orphans neon-postgres13
start-neon-js:
docker compose -f docker-compose.yml up --wait -d --remove-orphans neon-proxy

dev-neon-ws-postgres13: start-neon-postgres13 build-qe-napi build-connector-kit-js
cp $(CONFIG_PATH)/neon-ws-postgres13 $(CONFIG_FILE)
dev-neon-js: start-neon-js build-qe-napi build-connector-kit-js
cp $(CONFIG_PATH)/neon-js $(CONFIG_FILE)

test-neon-ws-postgres13: dev-neon-ws-postgres13 test-qe-st
test-neon-js: dev-neon-js test-qe-st

dev-neon-ws-postgres13-wasm: start-neon-postgres13 build-qe-wasm build-connector-kit-js
cp $(CONFIG_PATH)/neon-ws-postgres13-wasm $(CONFIG_FILE)
dev-neon-wasm: start-neon-js build-qe-wasm build-connector-kit-js
cp $(CONFIG_PATH)/neon-wasm $(CONFIG_FILE)

test-neon-ws-postgres13-wasm: dev-neon-ws-postgres13-wasm test-qe-st
test-neon-wasm: dev-neon-wasm test-qe-st

test-driver-adapter-neon: test-neon-ws-postgres13
test-driver-adapter-neon-wasm: test-neon-ws-postgres13-wasm
test-driver-adapter-neon: test-neon-js
test-driver-adapter-neon-wasm: test-neon-wasm

start-postgres14:
docker compose -f docker-compose.yml up --wait -d --remove-orphans postgres14
Expand Down Expand Up @@ -283,21 +283,21 @@ start-vitess_8_0:
dev-vitess_8_0: start-vitess_8_0
cp $(CONFIG_PATH)/vitess_8_0 $(CONFIG_FILE)

start-planetscale-vitess8:
docker compose -f docker-compose.yml up -d --remove-orphans planetscale-vitess8
start-planetscale-js:
docker compose -f docker-compose.yml up -d --remove-orphans planetscale-proxy

dev-planetscale-vitess8: start-planetscale-vitess8 build-qe-napi build-connector-kit-js
cp $(CONFIG_PATH)/planetscale-vitess8 $(CONFIG_FILE)
dev-planetscale-js: start-planetscale-js build-qe-napi build-connector-kit-js
cp $(CONFIG_PATH)/planetscale-js $(CONFIG_FILE)

test-planetscale-vitess8: dev-planetscale-vitess8 test-qe-st
test-planetscale-js: dev-planetscale-js test-qe-st

dev-planetscale-vitess8-wasm: start-planetscale-vitess8 build-qe-wasm build-connector-kit-js
cp $(CONFIG_PATH)/planetscale-vitess8-wasm $(CONFIG_FILE)
dev-planetscale-wasm: start-planetscale-js build-qe-wasm build-connector-kit-js
cp $(CONFIG_PATH)/planetscale-wasm $(CONFIG_FILE)

test-planetscale-vitess8-wasm: dev-planetscale-vitess8-wasm test-qe-st
test-planetscale-wasm: dev-planetscale-wasm test-qe-st

test-driver-adapter-planetscale: test-planetscale-vitess8
test-driver-adapter-planetscale-wasm: test-planetscale-vitess8-wasm
test-driver-adapter-planetscale: test-planetscale-js
test-driver-adapter-planetscale-wasm: test-planetscale-wasm

######################
# Local dev commands #
Expand Down
71 changes: 65 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ services:
networks:
- databases

neon-postgres13:
neon-proxy:
image: ghcr.io/neondatabase/wsproxy:latest
restart: unless-stopped
environment:
Expand All @@ -123,22 +123,69 @@ services:
networks:
- databases

planetscale-vitess8:
# Tests using a vitess backend were not running properly for query-engine tests, and In
# https://github.com/prisma/prisma-engines/pull/4423 work was done to have coverage of the correctness of planetscale
# driver adapters.
#
# Given these tests run against the planetscale proxy, and given a different test suite will exist for vitess with
# rust drivers, we opted for the path of least friction when running the driver adapter tests, which is putting a
# single mysql box behind the planetscale proxy instead of full vttest cluster.
#
# The tradeoffs are:
#
# - we don't exercise vitess but mysql. This is a close approximation, but there might be small differences in
# behavior. (ex. vttest can be returning different error messages than mysql)
#
# - however, we 1) do exercise the planetscale proxy, 2) we use relationMode=prisma and this resembles what actually
# happens within the query engine, where vitess does not exist as a provider, and as such there isn't any particular
# capability or conditional code making the engine behave differently then when using Mysql.
# In the end Vitess is just an abstraction existing in the test kit to a) use the mysql provider, b) run the suite
# with relationMode=prisma; c) being able to run or exclude specific tests for that configuration. But the existence
# of this testing connector is misleading, and it should probably be just a version of the MySQL testing connector
# instead.
planetscale-proxy:
build: ./docker/planetscale_proxy
environment:
MYSQL_HOST: 'vitess-test-8_0'
MYSQL_PORT: 33807
MYSQL_DATABASE: 'test'
MYSQL_HOST: 'mysql-planetscale'
MYSQL_PORT: 3306
MYSQL_DATABASE: prisma
ports:
- '8085:8085'
depends_on:
- vitess-test-8_0
mysql-planetscale:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: ['CMD', 'nc', '-z', '127.0.0.1', '8085']
interval: 5s
timeout: 2s
retries: 20
networks:
- databases

mysql-planetscale:
image: mysql:8.0.28
command: mysqld
restart: unless-stopped
platform: linux/x86_64
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: prisma
ports:
- '3310:3306'
networks:
- databases
tmpfs: /var/lib/planetscale-mysql
volumes:
- "./docker/planetscale-mysql/my.cnf:/etc/mysql/my.cnf"
ulimits:
nofile:
soft: 20000
hard: 40000
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
timeout: 20s
retries: 10

postgres14:
image: postgres:14
Expand Down Expand Up @@ -180,6 +227,10 @@ services:
networks:
- databases
tmpfs: /var/lib/mysql
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
timeout: 20s
retries: 10

mysql-5-7:
image: mysql:5.7.44
Expand All @@ -194,6 +245,10 @@ services:
networks:
- databases
tmpfs: /var/lib/mysql
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
timeout: 20s
retries: 10

mysql-8-0:
image: mysql:8.0.28
Expand All @@ -208,6 +263,10 @@ services:
networks:
- databases
tmpfs: /var/lib/mysql8
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
timeout: 20s
retries: 10

mariadb-10-0:
image: mariadb:10
Expand Down
33 changes: 18 additions & 15 deletions query-engine/connector-test-kit-rs/query-tests-setup/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
CockroachDbConnectorTag, ConnectorTag, ConnectorVersion, MongoDbConnectorTag, MySqlConnectorTag,
PostgresConnectorTag, SqlServerConnectorTag, SqliteConnectorTag, TestResult, VitessConnectorTag,
};
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use std::{convert::TryFrom, env, fmt::Display, fs::File, io::Read, path::PathBuf};

static TEST_CONFIG_FILE_NAME: &str = ".test_config";
Expand All @@ -27,34 +27,39 @@ impl Display for TestExecutor {
pub struct TestConfig {
/// The connector that tests should run for.
/// Env key: `TEST_CONNECTOR`
connector: String,
pub(crate) connector: String,

/// The connector version tests should run for.
/// If the test connector is versioned, this option is required.
/// Env key: `TEST_CONNECTOR_VERSION`
#[serde(rename = "version")]
connector_version: Option<String>,
pub(crate) connector_version: Option<String>,

/// An external process to execute the test queries and produced responses for assertion
/// Used when testing driver adapters, this process is expected to be a javascript process
/// loading the library engine (as a library, or WASM modules) and providing it with a
/// driver adapter.
/// Possible values: Napi, Wasm
/// Env key: `EXTERNAL_TEST_EXECUTOR`
external_test_executor: Option<TestExecutor>,
pub(crate) external_test_executor: Option<TestExecutor>,

/// The driver adapter to use when running tests, will be forwarded to the external test
/// executor by setting the `DRIVER_ADAPTER` env var when spawning the executor process
driver_adapter: Option<String>,
pub(crate) driver_adapter: Option<String>,

/// The driver adapter configuration to forward as a stringified JSON object to the external
/// test executor by setting the `DRIVER_ADAPTER_CONFIG` env var when spawning the executor
driver_adapter_config: Option<serde_json::Value>,
pub(crate) driver_adapter_config: Option<DriverAdapterConfig>,

/// Indicates whether or not the tests are running in CI context.
/// Env key: `BUILDKITE`
#[serde(default)]
is_ci: bool,
pub(crate) is_ci: bool,
}

#[derive(Debug, Default, Serialize, Deserialize)]
pub(crate) struct DriverAdapterConfig {
pub(crate) proxy_url: Option<String>,
}

const CONFIG_LOAD_FAILED: &str = r####"
Expand Down Expand Up @@ -125,7 +130,7 @@ impl TestConfig {
if let Some(external_test_executor) = self.external_test_executor.as_ref() {
println!("* External test executor: {}", external_test_executor);
println!("* Driver adapter: {}", self.driver_adapter().unwrap_or_default());
println!("* Driver adapter url override: {}", self.json_stringify_driver_adapter_config());
println!("* Driver adapter config: {}", self.json_stringify_driver_adapter_config());
}
println!("******************************");
}
Expand All @@ -139,7 +144,7 @@ impl TestConfig {

let driver_adapter = std::env::var("DRIVER_ADAPTER").ok();
let driver_adapter_config = std::env::var("DRIVER_ADAPTER_CONFIG")
.map(|config| serde_json::from_str::<serde_json::Value>(config.as_str()).ok())
.map(|config| serde_json::from_str::<DriverAdapterConfig>(config.as_str()).ok())
.unwrap_or_default();

// Just care for a set value for now.
Expand Down Expand Up @@ -204,7 +209,8 @@ impl TestConfig {
| Ok(ConnectorVersion::SqlServer(None))
| Ok(ConnectorVersion::MongoDb(None))
| Ok(ConnectorVersion::CockroachDb(None))
| Ok(ConnectorVersion::Postgres(None)) => {
| Ok(ConnectorVersion::Postgres(None))
| Ok(ConnectorVersion::Sqlite(None)) => {
exit_with_message("The current test connector requires a version to be set to run.");
}
Ok(ConnectorVersion::Vitess(Some(_)))
Expand Down Expand Up @@ -278,11 +284,8 @@ impl TestConfig {
self.driver_adapter.as_deref()
}

pub fn json_stringify_driver_adapter_config(&self) -> String {
self.driver_adapter_config
.as_ref()
.map(|value| value.to_string())
.unwrap_or("{}".to_string())
fn json_stringify_driver_adapter_config(&self) -> String {
serde_json::to_string(&self.driver_adapter_config).unwrap_or_default()
}

pub fn test_connector(&self) -> TestResult<(ConnectorTag, ConnectorVersion)> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"connector": "sqlite",
"version": "libsql.js",
"driver_adapter": "libsql",
"external_test_executor": "Napi"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"connector": "postgres",
"version": "13",
"version": "neon.js",
"driver_adapter": "neon:ws",
"driver_adapter_config": { "proxyUrl": "127.0.0.1:5488/v1" },
"driver_adapter_config": { "proxy_url": "127.0.0.1:5488/v1" },
"external_test_executor": "Napi"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"connector": "postgres",
"version": "13",
"driver_adapter": "neon:ws",
"driver_adapter_config": { "proxyUrl": "127.0.0.1:5488/v1" },
"driver_adapter_config": { "proxy_url": "127.0.0.1:5488/v1" },
"external_test_executor": "Wasm"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"connector": "postgres",
"version": "13",
"version": "pg.js",
"driver_adapter": "pg",
"external_test_executor": "Napi"
}

0 comments on commit d2779e4

Please sign in to comment.