()
| 18 | #[sea_orm_macros::test] |
| 19 | #[cfg(feature = "sqlx-mysql")] |
| 20 | pub async fn connection_ping_closed_mysql() { |
| 21 | let ctx = std::rc::Rc::new(Box::new(TestContext::new("connection_ping_closed").await)); |
| 22 | let ctx_ping = std::rc::Rc::clone(&ctx); |
| 23 | |
| 24 | ctx.db.get_mysql_connection_pool().close().await; |
| 25 | assert_eq!( |
| 26 | ctx_ping.db.ping().await, |
| 27 | Err(DbErr::ConnectionAcquire(ConnAcquireErr::ConnectionClosed)) |
| 28 | ); |
| 29 | |
| 30 | let base_url = std::env::var("DATABASE_URL").unwrap(); |
| 31 | let mut opt = sea_orm::ConnectOptions::new(format!("{base_url}/connection_ping_closed")); |
| 32 | opt |
| 33 | // The connection pool has a single connection only |
| 34 | .max_connections(1) |
| 35 | // A controlled connection acquire timeout |
| 36 | .acquire_timeout(std::time::Duration::from_secs(2)); |
| 37 | |
| 38 | let db = sea_orm::Database::connect(opt).await.unwrap(); |
| 39 | |
| 40 | async fn transaction_blocked(db: &DatabaseConnection) { |
| 41 | let _txn = sea_orm::TransactionTrait::begin(db).await.unwrap(); |
| 42 | // Occupy the only connection, thus forcing others fail to acquire connection |
| 43 | tokio::time::sleep(std::time::Duration::from_secs(3)).await; |
| 44 | } |
| 45 | |
| 46 | async fn transaction(db: &DatabaseConnection) { |
| 47 | // Should fail to acquire |
| 48 | let txn = sea_orm::TransactionTrait::begin(db).await; |
| 49 | assert_eq!( |
| 50 | txn.expect_err("should be a time out"), |
| 51 | crate::DbErr::ConnectionAcquire(ConnAcquireErr::Timeout) |
| 52 | ) |
| 53 | } |
| 54 | |
| 55 | tokio::join!(transaction_blocked(&db), transaction(&db)); |
| 56 | |
| 57 | ctx.delete().await; |
| 58 | } |
| 59 | |
| 60 | #[sea_orm_macros::test] |
| 61 | #[cfg(feature = "sqlx-sqlite")] |
nothing calls this directly
no test coverage detected