Skip to content

Commit

Permalink
Remove JS tags in favor of specific driver ones
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelff committed Nov 21, 2023
1 parent 58c4254 commit b7eb6d5
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use query_engine_tests::*;

#[test_suite(schema(generic))]
mod raw_params {
#[connector_test(only(Postgres), exclude(JS))]
#[connector_test(only(Postgres), exclude(Postgres("neon.js"), Postgres("pg.js")))]
async fn value_too_many_bind_variables(runner: Runner) -> TestResult<()> {
let n = 32768;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ mod max_integer {
schema.to_owned()
}

#[connector_test(schema(overflow_pg), only(Postgres), exclude(JS))]
#[connector_test(schema(overflow_pg), only(Postgres), exclude(Postgres("neon.js"), Postgres("pg.js")))]
async fn unfitted_int_should_fail_pg_quaint(runner: Runner) -> TestResult<()> {
// int
assert_error!(
Expand Down Expand Up @@ -235,7 +235,7 @@ mod max_integer {
}

// The driver adapter for neon provides different error messages on overflow
#[connector_test(schema(overflow_pg), only(JS, Postgres))]
#[connector_test(schema(overflow_pg), only(Postgres("neon.js"), Postgres("pg.js")))]
async fn unfitted_int_should_fail_pg_js(runner: Runner) -> TestResult<()> {
// int
assert_error!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod conversion_error {
schema.to_owned()
}

#[connector_test(schema(schema_int), only(Sqlite), exclude(JS))]
#[connector_test(schema(schema_int), only(Sqlite), exclude(Sqlite("libsql.js")))]
async fn convert_to_int_sqlite_quaint(runner: Runner) -> TestResult<()> {
create_test_data(&runner).await?;

Expand All @@ -38,7 +38,7 @@ mod conversion_error {
Ok(())
}

#[connector_test(schema(schema_int), only(Sqlite, JS))]
#[connector_test(schema(schema_int), only(Sqlite("libsql.js")))]
async fn convert_to_int_sqlite_js(runner: Runner) -> TestResult<()> {
create_test_data(&runner).await?;

Expand All @@ -52,7 +52,7 @@ mod conversion_error {
Ok(())
}

#[connector_test(schema(schema_bigint), only(Sqlite), exclude(JS))]
#[connector_test(schema(schema_bigint), only(Sqlite), exclude(Sqlite("libsql.js")))]
async fn convert_to_bigint_sqlite_quaint(runner: Runner) -> TestResult<()> {
create_test_data(&runner).await?;

Expand All @@ -66,7 +66,7 @@ mod conversion_error {
Ok(())
}

#[connector_test(schema(schema_bigint), only(Sqlite, JS))]
#[connector_test(schema(schema_bigint), only(Sqlite("libsql.js")))]
async fn convert_to_bigint_sqlite_js(runner: Runner) -> TestResult<()> {
create_test_data(&runner).await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ mod json {

// The external runner for driver adapters, in spite of the protocol being used in the test matrix
// uses the JSON representation of queries, so this test should not apply to driver adapters (exclude(JS))
#[connector_test(schema(json_opt), exclude(JS, MySQL(5.6)))]
#[connector_test(schema(json_opt), exclude(Vitess("planetscale.js"), MySQL(5.6)))]
async fn nested_not_shorthand(runner: Runner) -> TestResult<()> {
// Those tests pass with the JSON protocol because the entire object is parsed as JSON.
// They remain useful to ensure we don't ever allow a full JSON filter input object type at the schema level.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod casts {
//
// Bails with: ERROR: invalid input syntax for type integer: "42.51"
//
#[connector_test(only(Postgres), exclude(JS))]
#[connector_test(only(Postgres), exclude(Postgres("neon.js")))]
async fn query_numeric_casts(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query_pretty!(&runner, fmt_query_raw(r#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ mod raw_errors {
Ok(())
}

#[connector_test(schema(common_nullable_types), only(Postgres), exclude(JS))]
#[connector_test(
schema(common_nullable_types),
only(Postgres),
exclude(Postgres("neon.js"), Postgres("pg.js"))
)]
async fn list_param_for_scalar_column_should_not_panic_quaint(runner: Runner) -> TestResult<()> {
assert_error!(
runner,
Expand All @@ -49,7 +53,7 @@ mod raw_errors {
Ok(())
}

#[connector_test(schema(common_nullable_types), only(JS, Postgres))]
#[connector_test(schema(common_nullable_types), only(Postgres("neon.js"), Postgres("pg.js")))]
async fn list_param_for_scalar_column_should_not_panic_pg_js(runner: Runner) -> TestResult<()> {
assert_error!(
runner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ pub enum ConnectorVersion {
}

impl ConnectorVersion {
fn is_broader(&self, other: &ConnectorVersion) -> bool {
match (self, other) {
(Self::SqlServer(None), Self::SqlServer(_))
| (Self::Postgres(None), Self::Postgres(_))
| (Self::MySql(None), Self::MySql(_))
| (Self::MongoDb(None), Self::MongoDb(_))
| (Self::Sqlite(None), Self::Sqlite(_))
| (Self::CockroachDb(None), Self::CockroachDb(_))
| (Self::Vitess(None), Self::Vitess(_)) => true,
_ => false,
}
}

fn matches_pattern(&self, pat: &ConnectorVersion) -> bool {
use ConnectorVersion::*;

Expand Down Expand Up @@ -295,54 +308,47 @@ impl fmt::Display for ConnectorVersion {
/// Determines whether or not a test should run for the given enabled connectors and capabilities
/// a connector is required to have.
pub(crate) fn should_run(
connector: &ConnectorTag,
version: &ConnectorVersion,
only: &[(&str, Option<&str>)],
exclude: &[(&str, Option<&str>)],
capabilities: ConnectorCapabilities,
) -> bool {
let (connector, version) = CONFIG.test_connector().unwrap();

if !capabilities.is_empty() && !connector.capabilities().contains(capabilities) {
println!("Connector excluded. Missing required capability.");
return false;
}

let running_driver_adapters = CONFIG.external_test_executor().is_some();
let exclusions = exclude
.iter()
.filter_map(|c| ConnectorVersion::try_from(*c).ok())
.collect::<Vec<_>>();

// We skip tests that exclude JS driver adapters when an external test executor is configured.
// A test that you only want to run with rust drivers can be annotated with exclude(JS)
if running_driver_adapters && exclude.iter().any(|excl| excl.0.to_uppercase() == "JS") {
println!("Excluded test execution for JS driver adapters. Skipping test");
return false;
};
// we consume the JS token to prevent it from being used in the following checks
let exclude: Vec<_> = exclude.iter().filter(|excl| excl.0.to_uppercase() != "JS").collect();

// We only run tests that include JS driver adapters when an external test executor is configured.
// A test that you only want to run with js driver adapters can be annotated with only(JS)
if !running_driver_adapters && only.iter().any(|incl| incl.0.to_uppercase() == "JS") {
println!("Excluded test execution for rust driver adapters. Skipping test");
return false;
}
// we consume the JS token to prevent it from being used in the following checks
let only: Vec<_> = only.iter().filter(|incl| incl.0.to_uppercase() != "JS").collect();
let inclusions = only
.iter()
.filter_map(|c| ConnectorVersion::try_from(*c).ok())
.collect::<Vec<_>>();

if !only.is_empty() {
return only
.iter()
.any(|incl| ConnectorVersion::try_from(**incl).unwrap().matches_pattern(&version));
for exclusion in exclusions.iter() {
for inclusion in inclusions.iter() {
if exclusion.is_broader(inclusion) {
panic!("Error in connector test execution rules. `{exclusion}` in `excluded()` subsumes `{inclusion}` in `only()`");
}
}
}

if exclude.iter().any(|excl| {
ConnectorVersion::try_from(**excl)
.map_or(false, |connector_version| connector_version.matches_pattern(&version))
}) {
if exclusions.iter().any(|excl| excl.matches_pattern(version)) {
println!("Connector excluded. Skipping test.");
return false;
}

if !inclusions.is_empty() {
return inclusions.iter().any(|incl| incl.matches_pattern(version));
}

// FIXME: This skips vitess unless explicitly opted in. Replace with `true` when fixing
// https://github.com/prisma/client-planning/issues/332
running_driver_adapters || !matches!(version, ConnectorVersion::Vitess(_))
CONFIG.external_test_executor().is_some() || !matches!(version, ConnectorVersion::Vitess(_))
}

impl TryFrom<(&str, Option<&str>)> for ConnectorVersion {
Expand All @@ -362,3 +368,44 @@ impl TryFrom<(&str, Option<&str>)> for ConnectorVersion {
})
}
}

#[cfg(test)]
mod tests {
use crate::connector_tag::{PostgresConnectorTag, PostgresVersion};
use crate::{ConnectorTag, ConnectorVersion};

#[test]
#[rustfmt::skip]
fn test_should_run() {
let only = vec![("postgres", None)];
let exclude = vec![("postgres", Some("neon.js"))];
let postgres = &PostgresConnectorTag as ConnectorTag;
let neon = ConnectorVersion::Postgres(Some(PostgresVersion::NeonJs));
let pg = ConnectorVersion::Postgres(Some(PostgresVersion::PgJs));

assert!(!super::should_run(&postgres, &neon, &only, &exclude, Default::default()));
assert!(super::should_run(&postgres, &pg, &only, &exclude, Default::default()));
}

#[test]
#[should_panic]
fn test_should_run_wrong_definition_versionless() {
let only = vec![("postgres", None)];
let exclude = vec![("postgres", None)];
let postgres = &PostgresConnectorTag as ConnectorTag;
let neon = ConnectorVersion::Postgres(Some(PostgresVersion::NeonJs));

super::should_run(&postgres, &neon, &only, &exclude, Default::default());
}

#[test]
#[should_panic]
fn test_should_run_wrong_definition_wider_exclusion() {
let only = vec![("postgres", Some("neon.js"))];
let exclude = vec![("postgres", None)];
let postgres = &PostgresConnectorTag as ConnectorTag;
let neon = ConnectorVersion::Postgres(Some(PostgresVersion::NeonJs));

super::should_run(&postgres, &neon, &only, &exclude, Default::default());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ pub enum SqliteVersion {
LibsqlJS,
}

impl Default for SqliteVersion {
fn default() -> Self {
Self::V3
}
}

impl ToString for SqliteVersion {
fn to_string(&self) -> String {
match self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ impl ConnectorTagInterface for VitessConnectorTag {
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum VitessVersion {
V8_0,
// The planetscale driver adapter
PlanetscaleJs,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ fn run_relation_link_test_impl(
let required_capabilities_for_test = required_capabilities | caps;
let test_db_name = format!("{suite_name}_{test_name}_{i}");
let template = dm.datamodel().to_owned();
let (connector, version) = CONFIG.test_connector().unwrap();

if !should_run(only, exclude, required_capabilities_for_test) {
if !should_run(&connector, &version, only, exclude, required_capabilities_for_test) {
continue;
}

Expand Down Expand Up @@ -250,7 +251,9 @@ fn run_connector_test_impl(
referential_override: Option<String>,
test_fn: &dyn Fn(Runner) -> BoxFuture<'static, TestResult<()>>,
) {
if !should_run(only, exclude, capabilities) {
let (connector, version) = CONFIG.test_connector().unwrap();

if !should_run(&connector, &version, only, exclude, capabilities) {
return;
}

Expand Down

0 comments on commit b7eb6d5

Please sign in to comment.