From 09c328bb0d5ef687fe3dcaaf0f72ebb6913d814b Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Wed, 18 Aug 2021 17:53:59 +0800 Subject: [PATCH] Use smol async-runtime and require one of the supported runtime for integration tests --- .github/workflows/rust.yml | 26 ++++++++++++++++---------- Cargo.toml | 2 ++ sea-orm-macros/src/lib.rs | 2 +- src/entity/base_entity.rs | 18 +++++++++--------- src/executor/paginator.rs | 16 ++++++++-------- src/executor/select.rs | 8 ++++---- src/lib.rs | 2 -- src/query/json.rs | 2 +- tests/basic.rs | 2 ++ tests/common/mod.rs | 6 ++++-- {src => tests/common}/runtime.rs | 9 +-------- 11 files changed, 48 insertions(+), 45 deletions(-) rename {src => tests/common}/runtime.rs (72%) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e0f4e3e0..6c6e8516 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,9 +13,6 @@ jobs: test: name: Unit Test 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] steps: - uses: actions/checkout@v2 @@ -25,13 +22,14 @@ jobs: toolchain: stable override: true + - uses: Swatinem/rust-cache@v1 + - uses: actions-rs/cargo@v1 with: command: build args: > --all --exclude 'sea-orm-example-*' - --features default,runtime-${{ matrix.runtime }} - uses: actions-rs/cargo@v1 with: @@ -39,7 +37,6 @@ jobs: args: > --all --exclude 'sea-orm-example-*' - --features default,runtime-${{ matrix.runtime }} cli: name: CLI @@ -56,6 +53,8 @@ jobs: toolchain: stable override: true + - uses: Swatinem/rust-cache@v1 + - uses: actions-rs/cargo@v1 with: command: install @@ -69,8 +68,7 @@ jobs: DATABASE_URL: "sqlite::memory:" 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] + runtime: [async-std-native-tls, actix-native-tls, tokio-native-tls] steps: - uses: actions/checkout@v2 @@ -80,6 +78,8 @@ jobs: toolchain: stable override: true + - uses: Swatinem/rust-cache@v1 + - uses: actions-rs/cargo@v1 with: command: build @@ -100,7 +100,7 @@ jobs: strategy: matrix: version: [8.0, 5.7] - runtime: [async-std-native-tls] + runtime: [async-std-native-tls, actix-native-tls, tokio-native-tls] services: mysql: image: mysql:${{ matrix.version }} @@ -127,6 +127,8 @@ jobs: toolchain: stable override: true + - uses: Swatinem/rust-cache@v1 + - uses: actions-rs/cargo@v1 with: command: build @@ -147,7 +149,7 @@ jobs: strategy: matrix: version: [10.6] - runtime: [async-std-native-tls] + runtime: [async-std-native-tls, actix-native-tls, tokio-native-tls] services: mysql: image: mariadb:${{ matrix.version }} @@ -174,6 +176,8 @@ jobs: toolchain: stable override: true + - uses: Swatinem/rust-cache@v1 + - uses: actions-rs/cargo@v1 with: command: build @@ -194,7 +198,7 @@ jobs: strategy: matrix: version: [13.3, 12.7, 11.12, 10.17, 9.6.22] - runtime: [async-std-native-tls] + runtime: [async-std-native-tls, actix-native-tls, tokio-native-tls] services: postgres: image: postgres:${{ matrix.version }} @@ -218,6 +222,8 @@ jobs: toolchain: stable override: true + - uses: Swatinem/rust-cache@v1 + - uses: actions-rs/cargo@v1 with: command: build diff --git a/Cargo.toml b/Cargo.toml index b7c707ba..58e2c897 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,8 @@ serde_json = { version = "^1", optional = true } uuid = { version = "0.8", features = ["serde", "v4"], optional = true } [dev-dependencies] +smol = { version = "^1.2" } +smol-potat = { version = "^1.1" } async-std = { version = "^1.9", features = ["attributes"] } tokio = { version = "^1.6", features = ["full"] } actix-rt = { version = "2.2.0" } diff --git a/sea-orm-macros/src/lib.rs b/sea-orm-macros/src/lib.rs index a04d17a0..a2217aa8 100644 --- a/sea-orm-macros/src/lib.rs +++ b/sea-orm-macros/src/lib.rs @@ -99,7 +99,7 @@ pub fn test(_: TokenStream, input: TokenStream) -> TokenStream { #[test] #(#attrs)* fn #name() #ret { - ::sea_orm::block_on!(async { #body }) + crate::block_on!(async { #body }) } ) .into() diff --git a/src/entity/base_entity.rs b/src/entity/base_entity.rs index a810d7ac..e318da40 100644 --- a/src/entity/base_entity.rs +++ b/src/entity/base_entity.rs @@ -107,7 +107,7 @@ pub trait EntityTrait: EntityName { /// # /// use sea_orm::{entity::*, query::*, tests_cfg::cake}; /// - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// assert_eq!( /// cake::Entity::find().one(&db).await?, @@ -170,7 +170,7 @@ pub trait EntityTrait: EntityName { /// # /// use sea_orm::{entity::*, query::*, tests_cfg::cake}; /// - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// assert_eq!( /// cake::Entity::find_by_id(11).all(&db).await?, @@ -207,7 +207,7 @@ pub trait EntityTrait: EntityName { /// # /// use sea_orm::{entity::*, query::*, tests_cfg::cake_filling}; /// - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// assert_eq!( /// cake_filling::Entity::find_by_id((2, 3)).all(&db).await?, @@ -275,7 +275,7 @@ pub trait EntityTrait: EntityName { /// ..Default::default() /// }; /// - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// let insert_result = cake::Entity::insert(apple).exec(&db).await?; /// @@ -326,7 +326,7 @@ pub trait EntityTrait: EntityName { /// ..Default::default() /// }; /// - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// let insert_result = cake::Entity::insert_many(vec![apple, orange]).exec(&db).await?; /// @@ -378,7 +378,7 @@ pub trait EntityTrait: EntityName { /// ..Default::default() /// }; /// - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// assert_eq!( /// fruit::Entity::update(orange.clone()).exec(&db).await?, // Clone here because we need to assert_eq @@ -422,7 +422,7 @@ pub trait EntityTrait: EntityName { /// # /// use sea_orm::{entity::*, query::*, tests_cfg::fruit, sea_query::{Expr, Value}}; /// - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// let update_result = fruit::Entity::update_many() /// .col_expr(fruit::Column::CakeId, Expr::value(Value::Null)) @@ -471,7 +471,7 @@ pub trait EntityTrait: EntityName { /// ..Default::default() /// }; /// - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// let delete_result = fruit::Entity::delete(orange).exec(&db).await?; /// @@ -514,7 +514,7 @@ pub trait EntityTrait: EntityName { /// # /// use sea_orm::{entity::*, query::*, tests_cfg::fruit}; /// - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// let delete_result = fruit::Entity::delete_many() /// .filter(fruit::Column::Name.contains("Apple")) diff --git a/src/executor/paginator.rs b/src/executor/paginator.rs index cbf50bf5..0cc7acbc 100644 --- a/src/executor/paginator.rs +++ b/src/executor/paginator.rs @@ -97,7 +97,7 @@ where /// # use sea_orm::{error::*, MockDatabase, DbBackend}; /// # let owned_db = MockDatabase::new(DbBackend::Postgres).into_connection(); /// # let db = &owned_db; - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// use sea_orm::{entity::*, query::*, tests_cfg::cake}; /// let mut cake_pages = cake::Entity::find() @@ -125,7 +125,7 @@ where /// # use sea_orm::{error::*, MockDatabase, DbBackend}; /// # let owned_db = MockDatabase::new(DbBackend::Postgres).into_connection(); /// # let db = &owned_db; - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// use futures::TryStreamExt; /// use sea_orm::{entity::*, query::*, tests_cfg::cake}; @@ -203,7 +203,7 @@ mod tests { (db, num_items) } - #[sea_orm_macros::test] + #[smol_potat::test] async fn fetch_page() -> Result<(), DbErr> { let (db, pages) = setup(); @@ -233,7 +233,7 @@ mod tests { Ok(()) } - #[sea_orm_macros::test] + #[smol_potat::test] async fn fetch() -> Result<(), DbErr> { let (db, pages) = setup(); @@ -267,7 +267,7 @@ mod tests { Ok(()) } - #[sea_orm_macros::test] + #[smol_potat::test] async fn num_pages() -> Result<(), DbErr> { let (db, num_items) = setup_num_items(); @@ -299,7 +299,7 @@ mod tests { Ok(()) } - #[sea_orm_macros::test] + #[smol_potat::test] async fn next_and_cur_page() -> Result<(), DbErr> { let (db, _) = setup(); @@ -315,7 +315,7 @@ mod tests { Ok(()) } - #[sea_orm_macros::test] + #[smol_potat::test] async fn fetch_and_next() -> Result<(), DbErr> { let (db, pages) = setup(); @@ -350,7 +350,7 @@ mod tests { Ok(()) } - #[sea_orm_macros::test] + #[smol_potat::test] async fn into_stream() -> Result<(), DbErr> { let (db, pages) = setup(); diff --git a/src/executor/select.rs b/src/executor/select.rs index 9d355049..6196ec73 100644 --- a/src/executor/select.rs +++ b/src/executor/select.rs @@ -287,7 +287,7 @@ where /// num_of_cakes: i32, /// } /// - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// let res: Vec = cake::Entity::find().from_raw_sql( /// Statement::from_sql_and_values( @@ -352,7 +352,7 @@ where /// # /// use sea_orm::{entity::*, query::*, tests_cfg::cake}; /// - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// let res: Vec = cake::Entity::find().from_raw_sql( /// Statement::from_sql_and_values( @@ -404,7 +404,7 @@ where /// # /// use sea_orm::{entity::*, query::*, tests_cfg::cake}; /// - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// let _: Option = cake::Entity::find().from_raw_sql( /// Statement::from_sql_and_values( @@ -439,7 +439,7 @@ where /// # /// use sea_orm::{entity::*, query::*, tests_cfg::cake}; /// - /// # let _: Result<(), DbErr> = sea_orm::block_on!(async { + /// # let _: Result<(), DbErr> = smol::block_on(async { /// # /// let _: Vec = cake::Entity::find().from_raw_sql( /// Statement::from_sql_and_values( diff --git a/src/lib.rs b/src/lib.rs index 2451cb5a..93ec2545 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -207,8 +207,6 @@ pub mod error; mod executor; pub mod query; #[doc(hidden)] -pub mod runtime; -#[doc(hidden)] pub mod tests_cfg; mod util; diff --git a/src/query/json.rs b/src/query/json.rs index b1872ab6..589f0fad 100644 --- a/src/query/json.rs +++ b/src/query/json.rs @@ -143,7 +143,7 @@ mod tests { use crate::{entity::*, DbBackend, DbErr, MockDatabase}; use sea_query::Value; - #[sea_orm_macros::test] + #[smol_potat::test] async fn to_json_1() -> Result<(), DbErr> { let db = MockDatabase::new(DbBackend::Postgres) .append_query_results(vec![vec![maplit::btreemap! { diff --git a/tests/basic.rs b/tests/basic.rs index 8101d1f2..78e3f25c 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -1,3 +1,5 @@ +pub mod common; + #[allow(unused_imports)] use sea_orm::{entity::*, error::*, sea_query, tests_cfg::*, Database, DbConn}; diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 5729aabb..54630999 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,7 +1,9 @@ -pub mod setup; -use sea_orm::DatabaseConnection; pub mod bakery_chain; +pub mod runtime; +pub mod setup; + pub use bakery_chain::*; +use sea_orm::DatabaseConnection; use std::env; pub struct TestContext { diff --git a/src/runtime.rs b/tests/common/runtime.rs similarity index 72% rename from src/runtime.rs rename to tests/common/runtime.rs index 31d7b866..bc02f003 100644 --- a/src/runtime.rs +++ b/tests/common/runtime.rs @@ -1,11 +1,4 @@ -#[cfg(any( - feature = "runtime-async-std", - all( - not(feature = "runtime-async-std"), - not(feature = "runtime-actix"), - not(feature = "runtime-tokio"), - ), -))] +#[cfg(feature = "runtime-async-std")] #[macro_export] macro_rules! block_on { ($($expr:tt)*) => {