sea-orm/tests/connection_tests.rs
Clément Guiton 3ccb9cdbf7
Feat: Expose ping method from SQLx (#1627)
* feat: add connection.ping method

* fmt

* impl `ConnectionTrait::ping` method for `SchemaManagerConnection`

* Mock connection should always be online

* remove needless clippy lint

* fmt

* Remove needless instrument

* Update src/driver/sqlx_sqlite.rs

* <feat>(Ping) removed ping() from ConnectionTrait

* removed ping from transaction

* removed unused imports

* Revert

---------

Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>
Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
2023-06-01 18:21:38 +08:00

54 lines
1.6 KiB
Rust

pub mod common;
pub use common::{bakery_chain::*, setup::*, TestContext};
use pretty_assertions::assert_eq;
pub use sea_orm::entity::*;
pub use sea_orm::*;
#[sea_orm_macros::test]
#[cfg(any(
feature = "sqlx-mysql",
feature = "sqlx-sqlite",
feature = "sqlx-postgres"
))]
pub async fn connection_ping() {
let ctx = TestContext::new("connection_ping").await;
ctx.db.ping().await.unwrap();
ctx.delete().await;
}
#[sea_orm_macros::test]
#[cfg(feature = "sqlx-mysql")]
pub async fn connection_ping_closed_mysql() {
let ctx = std::rc::Rc::new(Box::new(TestContext::new("connection_ping_closed").await));
let ctx_ping = std::rc::Rc::clone(&ctx);
ctx.db.get_mysql_connection_pool().close().await;
assert_eq!(ctx_ping.db.ping().await, Err(DbErr::ConnectionAcquire));
ctx.delete().await;
}
#[sea_orm_macros::test]
#[cfg(feature = "sqlx-sqlite")]
pub async fn connection_ping_closed_sqlite() {
let ctx = std::rc::Rc::new(Box::new(TestContext::new("connection_ping_closed").await));
let ctx_ping = std::rc::Rc::clone(&ctx);
ctx.db.get_sqlite_connection_pool().close().await;
assert_eq!(ctx_ping.db.ping().await, Err(DbErr::ConnectionAcquire));
ctx.delete().await;
}
#[sea_orm_macros::test]
#[cfg(feature = "sqlx-postgres")]
pub async fn connection_ping_closed_postgres() {
let ctx = std::rc::Rc::new(Box::new(TestContext::new("connection_ping_closed").await));
let ctx_ping = std::rc::Rc::clone(&ctx);
ctx.db.get_postgres_connection_pool().close().await;
assert_eq!(ctx_ping.db.ping().await, Err(DbErr::ConnectionAcquire));
ctx.delete().await;
}