Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add TiDB into the engine tests #3308

Closed
wants to merge 62 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
9ed409a
test: add tidb 6.3 docker
Mini256 Oct 20, 2022
2c04cd0
test: add test setup for tidb
Mini256 Oct 20, 2022
4dba8b9
test: add tidb into the migration engine tests
Mini256 Oct 20, 2022
a4952f8
test: add tidb into the introspection engine tests
Mini256 Oct 20, 2022
17709f5
feat: add tidb into query engine tests
Mini256 Oct 20, 2022
95504db
fix ci
Mini256 Oct 26, 2022
49ab8b8
fix ci
Mini256 Oct 26, 2022
cf3e8e3
fix: add interactive_tx testcase for TiDB cause TiDB doesn't support …
Mini256 Nov 6, 2022
0b3b241
fix: add introspect_tidb_non_prisma testcase for TiDB cause TiDB does…
Mini256 Nov 6, 2022
a76d752
fix: not more skip update_json_adv testcase cause this issue has been…
Mini256 Nov 6, 2022
4cf3f51
fix: not more skip not_in_batching testcase cause QUERY_BATCH_SIZE=10…
Mini256 Nov 6, 2022
8177d21
fix: revert changes in advisory_locking_works testcase
Mini256 Nov 6, 2022
3ef6694
fix: add link for tidb_basic_repeatable_read testcase
Mini256 Nov 8, 2022
179b7f5
fix: add comment for metadata_for_tidb_should_work testcase
Mini256 Nov 11, 2022
949008f
fix: remove exclude for safe_casts_with_existing_data_should_work tes…
Mini256 Nov 12, 2022
c4469be
test: add testcase valid_isolation_level_tidb and no more exclude inv…
Mini256 Nov 12, 2022
b3d2d09
fix: add comment for primary_key_migrations_do_not_cause_data_loss te…
Mini256 Nov 13, 2022
802aad7
fix: include TiDB in the on_delete:no_action:delete_parent_violation …
Mini256 Nov 13, 2022
2aee982
Merge branch 'main' into fix-testes-for-tidb
Mini256 Nov 16, 2022
c4caaf8
fix: merge introspect_tidb/mysql_non_prisma testcase
Mini256 Nov 17, 2022
6998615
Merge branch 'main' into fix-testes-for-tidb
janpio Nov 25, 2022
ab065a9
Update introspection-engine/introspection-engine-tests/tests/tables/m…
Mini256 Dec 5, 2022
d649e0b
Update migration-engine/migration-engine-tests/tests/migrations/id.rs
Mini256 Dec 5, 2022
52d7328
address comment
Mini256 Dec 5, 2022
7725134
test: add tidb in the matrix of GitHub action and use tidb v6.5.0-pre…
Mini256 Dec 5, 2022
e7fe8b4
fix testes
Mini256 Dec 8, 2022
719c4d4
trigger testes
Mini256 Dec 9, 2022
570a9f2
Revert "trigger testes"
Mini256 Dec 9, 2022
c71c91d
fix: exclude tidb for relation with ignored referenced because of for…
Mini256 Dec 9, 2022
4754ccf
test: fix testcase in the mysql_describer_tests
Mini256 Dec 9, 2022
1f43ae1
test: exclude tidb from mysql_foreign_key_on_delete_must_be_handled c…
Mini256 Dec 9, 2022
add464d
Merge branch 'main' into fix-testes-for-tidb
Mini256 Dec 9, 2022
4e39a8e
test: `default` to `default_value_id` after merge base
Mini256 Dec 9, 2022
93c574c
Merge remote-tracking branch 'upstream/main' into fix-testes-for-tidb
Mini256 Apr 20, 2023
32946d8
fix: using TiDB 7.0 image and fix some new testes
Mini256 Apr 20, 2023
72328be
fix fmt
Mini256 Apr 20, 2023
10c9b4d
fix
Mini256 Apr 20, 2023
c478f33
Merge branch 'main' into fix-testes-for-tidb
Mini256 Apr 20, 2023
7e0eb8f
fix
Mini256 Apr 20, 2023
d88be52
fix fmt
Mini256 Apr 20, 2023
83d263d
Merge branch 'main' into fix-testes-for-tidb
Mini256 Apr 20, 2023
3110473
fix fmt
Mini256 Apr 20, 2023
41805c4
fix
Mini256 Apr 20, 2023
88d6dc1
fix
Mini256 Apr 20, 2023
806389c
fix
Mini256 Apr 20, 2023
7b329a4
fix: using 'docker compose'
Mini256 Apr 20, 2023
10773b1
fix: run occ test
Mini256 Apr 20, 2023
df32a87
fix: fix new testes on query engine and schema engines
Mini256 Apr 21, 2023
806cb25
Merge branch 'main' into fix-testes-for-tidb
Mini256 Apr 21, 2023
c89302c
fix fmt
Mini256 Apr 21, 2023
beba669
fix: remove exclude for foreign keys testes
Mini256 Apr 21, 2023
a18faf8
Merge branch 'main' into fix-testes-for-tidb
Mini256 Apr 21, 2023
65e2cd3
fix
Mini256 Apr 21, 2023
e3e0030
fix: fix having_filter test and remove exclude for fk test
Mini256 Apr 22, 2023
caf2b09
fix: fix adding_mutual_references_on_existing_tables_works test and e…
Mini256 Apr 24, 2023
ff26b96
try to use single threaded to run schema engine test
Mini256 Apr 24, 2023
25fdeb1
fix: skip get_lock for TiDB and refine some testes
Mini256 Apr 26, 2023
7d21e4f
fix fmt
Mini256 Apr 26, 2023
91da384
Merge branch 'main' into fix-testes-for-tidb
Mini256 Apr 26, 2023
f61ed22
fix
Mini256 Apr 26, 2023
20a6fab
Merge remote-tracking branch 'upstream/main' into fix-testes-for-tidb
Mini256 Jul 5, 2023
fed4a9b
feat: update the tidb image to v7.1.0
Mini256 Jul 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/query-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ jobs:
single_threaded: false
connector: "cockroachdb"
version: "22.1"
- name: "tidb"
single_threaded: false
connector: "tidb"
engine_protocol: [graphql, json]


env:
LOG_LEVEL: "info"
LOG_QUERIES: "y"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/schema-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ jobs:
url: "mysql://root:prisma@localhost:3307"
- name: mysql_mariadb
url: "mysql://root:prisma@localhost:3308"
- name: tidb
url: "mysql://root@localhost:4000"
single_threaded: true
- name: postgres9
url: "postgresql://postgres:prisma@localhost:5431"
- name: postgres10
Expand Down
2 changes: 2 additions & 0 deletions .test_database_urls/tidb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export TEST_DATABASE_URL="mysql://root@localhost:4000"
unset TEST_SHADOW_DATABASE_URL
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ start-mysql_mariadb:
dev-mariadb: start-mysql_mariadb
cp $(CONFIG_PATH)/mariadb $(CONFIG_FILE)

start-tidb:
docker compose -f docker-compose.yml up -d --remove-orphans tidb

dev-tidb: start-tidb
cp $(CONFIG_PATH)/tidb $(CONFIG_FILE)

start-mssql_2019:
docker compose -f docker-compose.yml up -d --remove-orphans mssql-2019

Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ services:
- databases
tmpfs: /var/lib/mariadb

tidb:
image: pingcap/tidb:v7.1.0
restart: always
platform: linux/x86_64
ports:
- "4000:4000"
networks:
- databases
tmpfs: /var/lib/tidb

vitess-test-5_7:
image: vitess/vttestserver:mysql57@sha256:53eea9d0189168b51bd8882f3684021fb1fc6bf40c919c18d9d667eded5ffbcb
restart: always
Expand Down
4 changes: 4 additions & 0 deletions libs/test-setup/src/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ pub(crate) fn get_mysql_tags(database_url: &str) -> Result<BitFlags<Tags>, Strin
if version.contains("MariaDB") {
tags |= Tags::Mariadb
} else {
if version.contains("TiDB") {
tags |= Tags::TiDB
}

if version.contains("vitess") {
tags |= Tags::Vitess;
}
Expand Down
1 change: 1 addition & 0 deletions libs/test-setup/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tags![
Postgres13 = 1 << 18,
CockroachDb221 = 1 << 19,
CockroachDb222 = 1 << 20,
TiDB = 1 << 21,
];

pub fn tags_from_comma_separated_list(input: &str) -> BitFlags<Tags> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ mod interactive_tx {
mod itx_isolation {
use query_engine_tests::*;

// All (SQL) connectors support serializable.
#[connector_test(exclude(MongoDb))]
// All (SQL) connectors except TiDB support serializable.
#[connector_test(exclude(MongoDb, TiDB))]
async fn basic_serializable(mut runner: Runner) -> TestResult<()> {
let tx_id = runner.start_tx(5000, 5000, Some("Serializable".to_owned())).await?;
runner.set_active_tx(tx_id.clone());
Expand All @@ -595,7 +595,7 @@ mod itx_isolation {
Ok(())
}

#[connector_test(exclude(MongoDb))]
#[connector_test(exclude(MongoDb, TiDB))]
async fn casing_doesnt_matter(mut runner: Runner) -> TestResult<()> {
let tx_id = runner.start_tx(5000, 5000, Some("sErIaLiZaBlE".to_owned())).await?;
runner.set_active_tx(tx_id.clone());
Expand Down Expand Up @@ -649,4 +649,39 @@ mod itx_isolation {

Ok(())
}

// TiDB supports repeatable read isolation level, but doesn't support serializable isolation level.
// Link: https://docs.pingcap.com/tidb/stable/transaction-isolation-levels#tidb-transaction-isolation-levels
#[connector_test(only(TiDB))]
async fn tidb_basic_repeatable_read(mut runner: Runner) -> TestResult<()> {
let tx_id = runner.start_tx(5000, 5000, Some("RepeatableRead".to_owned())).await?;
runner.set_active_tx(tx_id.clone());

insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneTestModel(data: { id: 1 }) { id }}"#),
@r###"{"data":{"createOneTestModel":{"id":1}}}"###
);

let res = runner.commit_tx(tx_id).await?;
assert!(res.is_ok());
runner.clear_active_tx();

insta::assert_snapshot!(
run_query!(&runner, r#"query { findManyTestModel { id field }}"#),
@r###"{"data":{"findManyTestModel":[{"id":1,"field":null}]}}"###
);

Ok(())
}

#[connector_test(only(TiDB))]
async fn tidb_casing_doesnt_matter(mut runner: Runner) -> TestResult<()> {
let tx_id = runner.start_tx(5000, 5000, Some("rEpEaTaBlErEaD".to_owned())).await?;
runner.set_active_tx(tx_id.clone());

let res = runner.commit_tx(tx_id).await?;
assert!(res.is_ok());

Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ mod metrics {
MongoDb(_) => assert_eq!(total_queries, 5),
CockroachDb => (), // not deterministic
MySql(_) => assert_eq!(total_queries, 12),
TiDB => assert_eq!(total_queries, 12),
Vitess(_) => assert_eq!(total_queries, 11),
Postgres(_) => assert_eq!(total_queries, 14),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use query_engine_tests::test_suite;

#[test_suite(capabilities(MultiSchema), exclude(Mysql))]
#[test_suite(capabilities(MultiSchema), exclude(Mysql, TiDB))]
mod multi_schema {
use query_engine_tests::*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use indoc::indoc;
use query_engine_tests::*;

#[test_suite(suite = "setdefault_onD_1to1_req", exclude(MongoDb, MySQL))]
#[test_suite(suite = "setdefault_onD_1to1_req", exclude(MongoDb, MySQL, TiDB))]
Mini256 marked this conversation as resolved.
Show resolved Hide resolved
mod one2one_req {
fn required_with_default() -> String {
let schema = indoc! {
Expand Down Expand Up @@ -103,7 +103,7 @@ mod one2one_req {
}
}

#[test_suite(suite = "setdefault_onD_1to1_opt", exclude(MongoDb, MySQL))]
#[test_suite(suite = "setdefault_onD_1to1_opt", exclude(MongoDb, MySQL, TiDB))]
mod one2one_opt {
fn optional_with_default() -> String {
let schema = indoc! {
Expand Down Expand Up @@ -206,7 +206,7 @@ mod one2one_opt {
}
}

#[test_suite(suite = "setdefault_onD_1toM_req", exclude(MongoDb, MySQL))]
#[test_suite(suite = "setdefault_onD_1toM_req", exclude(MongoDb, MySQL, TiDB))]
mod one2many_req {
fn required_with_default() -> String {
let schema = indoc! {
Expand Down Expand Up @@ -307,7 +307,7 @@ mod one2many_req {
}
}

#[test_suite(suite = "setdefault_onD_1toM_opt", exclude(MongoDb, MySQL))]
#[test_suite(suite = "setdefault_onD_1toM_opt", exclude(MongoDb, MySQL, TiDB))]
mod one2many_opt {
fn optional_with_default() -> String {
let schema = indoc! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use indoc::indoc;
use query_engine_tests::*;

#[test_suite(suite = "setdefault_onU_1to1_req", exclude(MongoDb, MySQL))]
#[test_suite(suite = "setdefault_onU_1to1_req", exclude(MongoDb, MySQL, TiDB))]
mod one2one_req {
fn required_with_default() -> String {
let schema = indoc! {
Expand Down Expand Up @@ -105,7 +105,7 @@ mod one2one_req {
}
}

#[test_suite(suite = "setdefault_onU_1to1_opt", exclude(MongoDb, MySQL))]
#[test_suite(suite = "setdefault_onU_1to1_opt", exclude(MongoDb, MySQL, TiDB))]
mod one2one_opt {
fn optional_with_default() -> String {
let schema = indoc! {
Expand Down Expand Up @@ -210,7 +210,7 @@ mod one2one_opt {
}
}

#[test_suite(suite = "setdefault_onU_1toM_req", exclude(MongoDb, MySQL))]
#[test_suite(suite = "setdefault_onU_1toM_req", exclude(MongoDb, MySQL, TiDB))]
mod one2many_req {
fn required_with_default() -> String {
let schema = indoc! {
Expand Down Expand Up @@ -313,7 +313,7 @@ mod one2many_req {
}
}

#[test_suite(suite = "setdefault_onU_1toM_opt", exclude(MongoDb, MySQL))]
#[test_suite(suite = "setdefault_onU_1toM_opt", exclude(MongoDb, MySQL, TiDB))]
mod one2many_opt {
fn optional_with_default() -> String {
let schema = indoc! {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use query_engine_tests::*;

#[test_suite(schema(schema), only(MySql))]
#[test_suite(schema(schema), only(MySql, TiDB))]
Mini256 marked this conversation as resolved.
Show resolved Hide resolved
mod prisma_ref_integrity {
fn schema() -> String {
let schema = indoc! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mod aggr_group_by_having {
_sum { int }
}
}"#,
MongoDb(_) => vec![
MongoDb(_) | TiDB => vec![
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also related to the default order issue: pingcap/tidb#37285

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the linked issue was resolved, but unclear if the underlying problem is now gone as well.

r#"{"data":{"groupByTestModel":[{"string":"group2","int":5,"_count":{"_all":1},"_sum":{"int":5}},{"string":"group1","int":5,"_count":{"_all":1},"_sum":{"int":5}}]}}"#,
r#"{"data":{"groupByTestModel":[{"string":"group1","int":5,"_count":{"_all":1},"_sum":{"int":5}},{"string":"group2","int":5,"_count":{"_all":1},"_sum":{"int":5}}]}}"#
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ mod isb {
}

// "batching of IN queries" should "work when having more than the specified amount of items"
#[connector_test]
// Exclude TiDB, TiDB does not guarantee the order of results returned when the `ORDER BY`
// clause is not specified
#[connector_test(exclude(TiDB))]
Comment on lines +38 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an issue for this?

async fn in_more_items(runner: Runner) -> TestResult<()> {
create_test_data(&runner).await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ mod transactional {
Ok(())
}

#[connector_test(exclude(MongoDb))]
#[connector_test(exclude(MongoDb, TiDB))]
async fn valid_isolation_level(runner: Runner) -> TestResult<()> {
let queries = vec![r#"mutation { createOneModelB(data: { id: 1 }) { id }}"#.to_string()];

Expand All @@ -115,6 +115,18 @@ mod transactional {
Ok(())
}

// TiDB supports repeatable read isolation level, but doesn't support serializable isolation level.
#[connector_test(only(TiDB))]
async fn valid_isolation_level_tidb(runner: Runner) -> TestResult<()> {
let queries = vec![r#"mutation { createOneModelB(data: { id: 1 }) { id }}"#.to_string()];

let batch_results = runner.batch(queries, true, Some("RepeatableRead".into())).await?;

insta::assert_snapshot!(batch_results.to_string(), @r###"{"batchResult":[{"data":{"createOneModelB":{"id":1}}}]}"###);

Ok(())
}

#[connector_test(exclude(MongoDb))]
async fn invalid_isolation_level(runner: Runner) -> TestResult<()> {
let queries = vec![r#"mutation { createOneModelB(data: { id: 1 }) { id }}"#.to_string()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ mod ext_rel_filters {
}

// MySql is case insensitive and Postgres case sensitive
#[connector_test(only(MySQL))]
#[connector_test(only(MySQL, TiDB))]
async fn mysql_rel1_many_filters(runner: Runner) -> TestResult<()> {
test_data(&runner).await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod having_filter {
string2
}
}"#,
MongoDb(_) => vec![
MongoDb(_) | TiDB => vec![
r#"{"data":{"groupByTestModel":[{"string":"group1","string2":"group1"},{"string":"group2","string2":"group2"}]}}"#,
r#"{"data":{"groupByTestModel":[{"string":"group2","string2":"group2"},{"string":"group1","string2":"group1"}]}}"#
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ mod json_filter {
fn json_path(runner: &Runner) -> &'static str {
match runner.connector_version() {
ConnectorVersion::Postgres(_) | ConnectorVersion::CockroachDb => r#"path: ["a", "b"]"#,
ConnectorVersion::MySql(_) => r#"path: "$.a.b""#,
ConnectorVersion::MySql(_) | ConnectorVersion::TiDB => r#"path: "$.a.b""#,
x => unreachable!("JSON filtering is not supported on {:?}", x),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use query_engine_tests::*;
#[test_suite(schema(schema))]
mod fr_one_to_m {
use indoc::indoc;
use query_engine_tests::run_query;
use query_engine_tests::{is_one_of, run_query};

fn schema() -> String {
let schema = indoc! { "
Expand Down Expand Up @@ -65,10 +65,22 @@ mod fr_one_to_m {
@r###"{"data":{"findManyCompany":[{"id":135}]}}"###
);

insta::assert_snapshot!(
run_query!(&runner, r#"query { findManyLocation(where: { company: { is: { id: { equals: 135 }}}}){ id }}"#),
@r###"{"data":{"findManyLocation":[{"id":311},{"id":314}]}}"###
);
match runner.connector_version() {
ConnectorVersion::TiDB => is_one_of!(
run_query!(
&runner,
r#"query { findManyLocation(where: { company: { is: { id: { equals: 135 }}}}){ id }}"#
),
vec![
r#"{"data":{"findManyLocation":[{"id":311},{"id":314}]}}"#,
r#"{"data":{"findManyLocation":[{"id":314},{"id":311}]}}"#
Mini256 marked this conversation as resolved.
Show resolved Hide resolved
]
),
_ => insta::assert_snapshot!(
run_query!(&runner, r#"query { findManyLocation(where: { company: { is: { id: { equals: 135 }}}}){ id }}"#),
@r###"{"data":{"findManyLocation":[{"id":311},{"id":314}]}}"###
),
};

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ mod json_filters {
Ok(())
}

#[connector_test(capabilities(JsonFilteringJsonPath), only(MySql(5.7), MySql(8)))]
#[connector_test(capabilities(JsonFilteringJsonPath), only(MySql(5.7), MySql(8), TiDB))]
async fn extract_json_path(runner: Runner) -> TestResult<()> {
create_row(&runner, 1, r#"{ \"a\": { \"b\": \"c\" } }"#, false).await?;
create_row(&runner, 2, r#"{ \"a\": { \"b\": [1, 2, 3] } }"#, false).await?;
Expand Down Expand Up @@ -223,8 +223,8 @@ mod json_filters {
);

match runner.connector_version() {
// MariaDB does not support finding arrays in arrays, unlike MySQL
ConnectorVersion::MySql(Some(MySqlVersion::MariaDb)) => {
// MariaDB / TiDB does not support finding arrays in arrays, unlike MySQL
ConnectorVersion::MySql(Some(MySqlVersion::MariaDb)) | ConnectorVersion::TiDB => {
insta::assert_snapshot!(
run_query!(
runner,
Expand Down Expand Up @@ -896,7 +896,7 @@ mod json_filters {
fn json_path(runner: &Runner) -> &'static str {
match runner.connector_version() {
ConnectorVersion::Postgres(_) | ConnectorVersion::CockroachDb => r#"path: ["a", "b"]"#,
ConnectorVersion::MySql(_) => r#"path: "$.a.b""#,
ConnectorVersion::MySql(_) | ConnectorVersion::TiDB => r#"path: "$.a.b""#,
x => unreachable!("JSON filtering is not supported on {:?}", x),
}
}
Expand Down
Loading
Loading