()
| 60 | #[sea_orm_macros::test] |
| 61 | #[cfg(feature = "sqlx-sqlite")] |
| 62 | pub async fn connection_ping_closed_sqlite() { |
| 63 | let ctx = std::rc::Rc::new(Box::new(TestContext::new("connection_ping_closed").await)); |
| 64 | let ctx_ping = std::rc::Rc::clone(&ctx); |
| 65 | |
| 66 | ctx.db.get_sqlite_connection_pool().close().await; |
| 67 | assert_eq!( |
| 68 | ctx_ping.db.ping().await, |
| 69 | Err(DbErr::ConnectionAcquire(ConnAcquireErr::ConnectionClosed)) |
| 70 | ); |
| 71 | |
| 72 | let base_url = std::env::var("DATABASE_URL").unwrap(); |
| 73 | let mut opt = sea_orm::ConnectOptions::new(base_url); |
| 74 | opt |
| 75 | // The connection pool has a single connection only |
| 76 | .max_connections(1) |
| 77 | // A controlled connection acquire timeout |
| 78 | .acquire_timeout(std::time::Duration::from_secs(2)); |
| 79 | |
| 80 | let db = sea_orm::Database::connect(opt).await.unwrap(); |
| 81 | |
| 82 | async fn transaction_blocked(db: &DatabaseConnection) { |
| 83 | let _txn = sea_orm::TransactionTrait::begin(db).await.unwrap(); |
| 84 | // Occupy the only connection, thus forcing others fail to acquire connection |
| 85 | tokio::time::sleep(std::time::Duration::from_secs(3)).await; |
| 86 | } |
| 87 | |
| 88 | async fn transaction(db: &DatabaseConnection) { |
| 89 | // Should fail to acquire |
| 90 | let txn = sea_orm::TransactionTrait::begin(db).await; |
| 91 | assert_eq!( |
| 92 | txn.expect_err("should be a time out"), |
| 93 | crate::DbErr::ConnectionAcquire(ConnAcquireErr::Timeout) |
| 94 | ) |
| 95 | } |
| 96 | |
| 97 | tokio::join!(transaction_blocked(&db), transaction(&db)); |
| 98 | |
| 99 | ctx.delete().await; |
| 100 | } |
| 101 | |
| 102 | #[sea_orm_macros::test] |
| 103 | #[cfg(feature = "sqlx-postgres")] |
nothing calls this directly
no test coverage detected