Testing different db on various async runtime (#53)

* Testing different db on various async runtime

* Test on various runtime

* No explicit cargo build step

* Cargo build with features

* Hotfix

* With actix_rt

* Only tests "runtime-async-std-native-tls" for now
This commit is contained in:
Billy Chan 2021-07-22 19:23:21 +08:00 committed by GitHub
parent f75fcd8fdf
commit 1cdbcceddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 170 additions and 20 deletions

View File

@ -15,6 +15,86 @@ jobs:
test: test:
name: Unit Test name: Unit Test
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
strategy:
matrix:
# runtime: [async-std-native-tls, async-std-rustls, actix-native-tls, actix-rustls, tokio-native-tls, tokio-rustls]
runtime: [async-std-native-tls]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-test-${{ matrix.runtime }}-${{ hashFiles('**/Cargo.lock') }}
- uses: actions-rs/cargo@v1
with:
command: build
args: >
--all
--features default,runtime-${{ matrix.runtime }}
- uses: actions-rs/cargo@v1
with:
command: test
args: >
--all
--features default,runtime-${{ matrix.runtime }}
sqlite:
name: SQLite
runs-on: ubuntu-20.04
strategy:
matrix:
# runtime: [async-std-native-tls, async-std-rustls, actix-native-tls, actix-rustls, tokio-native-tls, tokio-rustls]
runtime: [async-std-native-tls]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-sqlite-${{ matrix.runtime }}-${{ hashFiles('**/Cargo.lock') }}
- uses: actions-rs/cargo@v1
with:
command: build
args: >
--all
--features default,runtime-${{ matrix.runtime }}
- uses: actions-rs/cargo@v1
with:
command: test
args: >
--all
--features default,sqlx-sqlite,runtime-${{ matrix.runtime }}
postgres:
name: Postgres
runs-on: ubuntu-20.04
strategy:
matrix:
# runtime: [async-std-native-tls, async-std-rustls, actix-native-tls, actix-rustls, tokio-native-tls, tokio-rustls]
runtime: [async-std-native-tls]
services: services:
postgres: postgres:
image: postgres:11 image: postgres:11
@ -38,11 +118,24 @@ jobs:
toolchain: stable toolchain: stable
override: true override: true
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-postgres-${{ matrix.runtime }}-${{ hashFiles('**/Cargo.lock') }}
- uses: actions-rs/cargo@v1 - uses: actions-rs/cargo@v1
with: with:
command: build command: build
args: >
--all
--features default,runtime-${{ matrix.runtime }}
- uses: actions-rs/cargo@v1 - uses: actions-rs/cargo@v1
with: with:
command: test command: test
args: --all args: >
--all
--features default,sqlx-postgres,runtime-${{ matrix.runtime }}

View File

@ -46,9 +46,11 @@ serde_json = { version = "^1", optional = true }
[dev-dependencies] [dev-dependencies]
async-std = { version = "^1.9", features = [ "attributes" ] } async-std = { version = "^1.9", features = [ "attributes" ] }
tokio = { version = "^1.6", features = ["full"] }
actix-rt = { version = "2.2.0" }
maplit = { version = "^1" } maplit = { version = "^1" }
rust_decimal_macros = { version = "^1" } rust_decimal_macros = { version = "^1" }
sea-orm = { path = ".", features = ["sqlx-postgres", "sqlx-sqlite", "sqlx-json", "sqlx-chrono", "sqlx-decimal", "runtime-async-std-native-tls", "debug-print"] } sea-orm = { path = ".", features = ["sqlx-json", "sqlx-chrono", "sqlx-decimal", "debug-print"] }
[features] [features]
debug-print = [] debug-print = []
@ -66,9 +68,27 @@ sqlx-decimal = [ "sqlx/decimal", "with-rust_decimal" ]
sqlx-mysql = [ "sqlx-dep", "sea-query/sqlx-mysql", "sqlx/mysql" ] sqlx-mysql = [ "sqlx-dep", "sea-query/sqlx-mysql", "sqlx/mysql" ]
sqlx-postgres = [ "sqlx-dep", "sea-query/sqlx-postgres", "sqlx/postgres" ] sqlx-postgres = [ "sqlx-dep", "sea-query/sqlx-postgres", "sqlx/postgres" ]
sqlx-sqlite = [ "sqlx-dep", "sea-query/sqlx-sqlite", "sqlx/sqlite" ] sqlx-sqlite = [ "sqlx-dep", "sea-query/sqlx-sqlite", "sqlx/sqlite" ]
runtime-actix-native-tls = [ "sqlx/runtime-actix-native-tls" ] runtime-async-std = []
runtime-async-std-native-tls = [ "sqlx/runtime-async-std-native-tls" ] runtime-async-std-native-tls = [ "sqlx/runtime-async-std-native-tls", "runtime-async-std" ]
runtime-tokio-native-tls = [ "sqlx/runtime-tokio-native-tls" ] runtime-async-std-rustls = [ "sqlx/runtime-async-std-rustls", "runtime-async-std" ]
runtime-actix-rustls = [ "sqlx/runtime-actix-rustls" ] runtime-actix = []
runtime-async-std-rustls = [ "sqlx/runtime-async-std-rustls" ] runtime-actix-native-tls = [ "sqlx/runtime-actix-native-tls", "runtime-actix" ]
runtime-tokio-rustls = [ "sqlx/runtime-tokio-rustls" ] runtime-actix-rustls = [ "sqlx/runtime-actix-rustls", "runtime-actix" ]
runtime-tokio = []
runtime-tokio-native-tls = [ "sqlx/runtime-tokio-native-tls", "runtime-tokio" ]
runtime-tokio-rustls = [ "sqlx/runtime-tokio-rustls", "runtime-tokio" ]
[[test]]
name = "sqlite-basic"
path = "tests/basic.rs"
required-features = ["sqlx-sqlite"]
[[test]]
name = "sqlite"
path = "tests/bakery_chain_tests.rs"
required-features = ["sqlx-sqlite"]
[[test]]
name = "postgres"
path = "tests/pg_tests.rs"
required-features = ["sqlx-postgres"]

View File

@ -5,5 +5,5 @@ edition = "2018"
publish = false publish = false
[dependencies] [dependencies]
sea-orm = { path = "../../", features = [ "sqlx-mysql", "runtime-async-std-native-tls", "debug-print" ] } sea-orm = { path = "../../" }
strum = { version = "^0.20", features = [ "derive" ] } strum = { version = "^0.20", features = [ "derive" ] }

View File

@ -6,7 +6,7 @@ publish = false
[dependencies] [dependencies]
async-std = { version = "^1.9", features = [ "attributes" ] } async-std = { version = "^1.9", features = [ "attributes" ] }
sea-orm = { path = "../../", features = [ "sqlx-mysql", "runtime-async-std-native-tls", "debug-print" ] } sea-orm = { path = "../../" }
sea-orm-codegen = { path = "../../sea-orm-codegen" } sea-orm-codegen = { path = "../../sea-orm-codegen" }
sea-query = { version = "^0.12" } sea-query = { version = "^0.12" }
strum = { version = "^0.20", features = [ "derive" ] } strum = { version = "^0.20", features = [ "derive" ] }

View File

@ -6,7 +6,7 @@ publish = false
[dependencies] [dependencies]
async-std = { version = "^1.9", features = [ "attributes" ] } async-std = { version = "^1.9", features = [ "attributes" ] }
sea-orm = { path = "../../", features = [ "sqlx-mysql", "runtime-async-std-native-tls", "debug-print", "sqlx-json", "macros" ], default-features = false } sea-orm = { path = "../../" }
serde_json = { version = "^1" } serde_json = { version = "^1" }
futures = { version = "^0.3" } futures = { version = "^0.3" }
async-stream = { version = "^0.3" } async-stream = { version = "^0.3" }

View File

@ -16,9 +16,9 @@ name = "sea_orm_codegen"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
sea-schema = { version = "^0.2", default-features = false, features = [ "sqlx-mysql", "runtime-async-std-native-tls", "discovery", "writer" ] } sea-schema = { version = "^0.2", default-features = false, features = [ "sqlx-mysql", "discovery", "writer" ] }
sea-query = { version = "^0.12" } sea-query = { version = "^0.12" }
sqlx = { version = "^0.5", features = [ "mysql", "runtime-async-std-native-tls" ] } sqlx = { version = "^0.5", default-features = false, features = [ "mysql" ] }
syn = { version = "^1", default-features = false, features = [ "derive", "parsing", "proc-macro", "printing" ] } syn = { version = "^1", default-features = false, features = [ "derive", "parsing", "proc-macro", "printing" ] }
quote = "^1" quote = "^1"
heck = "^0.3" heck = "^0.3"
@ -26,4 +26,30 @@ proc-macro2 = "^1"
[dev-dependencies] [dev-dependencies]
async-std = { version = "^1.9", features = [ "attributes" ] } async-std = { version = "^1.9", features = [ "attributes" ] }
sea-orm = { path = "../", features = ["mock", "sqlx-json", "sqlx-chrono", "runtime-async-std-native-tls"] } sea-orm = { path = "../" }
[features]
runtime-actix-native-tls = [
"sqlx/runtime-actix-native-tls",
"sea-schema/runtime-actix-native-tls",
]
runtime-async-std-native-tls = [
"sqlx/runtime-async-std-native-tls",
"sea-schema/runtime-async-std-native-tls",
]
runtime-tokio-native-tls = [
"sqlx/runtime-tokio-native-tls",
"sea-schema/runtime-tokio-native-tls",
]
runtime-actix-rustls = [
"sqlx/runtime-actix-rustls",
"sea-schema/runtime-actix-rustls",
]
runtime-async-std-rustls = [
"sqlx/runtime-async-std-rustls",
"sea-schema/runtime-async-std-rustls",
]
runtime-tokio-rustls = [
"sqlx/runtime-tokio-rustls",
"sea-schema/runtime-tokio-rustls",
]

View File

@ -1,6 +1,4 @@
use crate::{ use crate::{error::*, ActiveModelTrait, DatabaseConnection, Insert, Statement};
error::*, ActiveModelTrait, DatabaseConnection, EntityTrait, Insert, Iterable, Statement,
};
use sea_query::InsertStatement; use sea_query::InsertStatement;
use std::future::Future; use std::future::Future;
@ -18,6 +16,7 @@ impl<A> Insert<A>
where where
A: ActiveModelTrait, A: ActiveModelTrait,
{ {
#[allow(unused_mut)]
pub fn exec( pub fn exec(
self, self,
db: &DatabaseConnection, db: &DatabaseConnection,
@ -26,6 +25,7 @@ where
let mut query = self.query; let mut query = self.query;
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
if let DatabaseConnection::SqlxPostgresPoolConnection(_) = db { if let DatabaseConnection::SqlxPostgresPoolConnection(_) = db {
use crate::{EntityTrait, Iterable};
use sea_query::{Alias, Expr, Query}; use sea_query::{Alias, Expr, Query};
for key in <A::Entity as EntityTrait>::PrimaryKey::iter() { for key in <A::Entity as EntityTrait>::PrimaryKey::iter() {
query.returning( query.returning(

View File

@ -133,6 +133,7 @@ macro_rules! try_getable_unsigned {
row.try_get(column.as_str()) row.try_get(column.as_str())
.map_err(crate::sqlx_error_to_query_err) .map_err(crate::sqlx_error_to_query_err)
} }
#[cfg(feature = "sqlx-postgres")]
QueryResultRow::SqlxPostgres(_) => { QueryResultRow::SqlxPostgres(_) => {
panic!("{} unsupported by sqlx-postgres", stringify!($type)) panic!("{} unsupported by sqlx-postgres", stringify!($type))
} }
@ -160,6 +161,7 @@ macro_rules! try_getable_unsigned {
Err(_) => Ok(None), Err(_) => Ok(None),
} }
} }
#[cfg(feature = "sqlx-postgres")]
QueryResultRow::SqlxPostgres(_) => { QueryResultRow::SqlxPostgres(_) => {
panic!("{} unsupported by sqlx-postgres", stringify!($type)) panic!("{} unsupported by sqlx-postgres", stringify!($type))
} }

View File

@ -6,8 +6,11 @@ pub use bakery_chain::*;
mod crud; mod crud;
mod schema; mod schema;
#[async_std::test]
// cargo test --test bakery_chain_tests -- --nocapture // cargo test --test bakery_chain_tests -- --nocapture
#[cfg_attr(feature = "runtime-async-std", async_std::main)]
#[cfg_attr(feature = "runtime-actix", actix_rt::main)]
#[cfg_attr(feature = "runtime-tokio", tokio::main)]
#[cfg(feature = "sqlx-sqlite")]
async fn main() { async fn main() {
let db: DbConn = setup::setup().await; let db: DbConn = setup::setup().await;
setup_schema(&db).await; setup_schema(&db).await;

View File

@ -2,8 +2,11 @@ use sea_orm::{entity::*, error::*, sea_query, tests_cfg::*, DbBackend, DbConn, S
mod setup; mod setup;
#[async_std::test]
// cargo test --test basic -- --nocapture // cargo test --test basic -- --nocapture
#[cfg_attr(feature = "runtime-async-std", async_std::main)]
#[cfg_attr(feature = "runtime-actix", actix_rt::main)]
#[cfg_attr(feature = "runtime-tokio", tokio::main)]
#[cfg(feature = "sqlx-sqlite")]
async fn main() { async fn main() {
let db: DbConn = setup::setup().await; let db: DbConn = setup::setup().await;

View File

@ -8,7 +8,10 @@ pub use bakery_chain::*;
use sea_query::{ColumnDef, TableCreateStatement}; use sea_query::{ColumnDef, TableCreateStatement};
// cargo test --test pg_tests -- --nocapture // cargo test --test pg_tests -- --nocapture
#[async_std::test] #[cfg_attr(feature = "runtime-async-std", async_std::main)]
#[cfg_attr(feature = "runtime-actix", actix_rt::main)]
#[cfg_attr(feature = "runtime-tokio", tokio::main)]
#[cfg(feature = "sqlx-postgres")]
async fn main() { async fn main() {
let base_url = "postgres://root:root@localhost"; let base_url = "postgres://root:root@localhost";
let db_name = "bakery_chain_schema_crud_tests"; let db_name = "bakery_chain_schema_crud_tests";