()
| 102 | #[sea_orm_macros::test] |
| 103 | #[cfg(feature = "sqlx-postgres")] |
| 104 | pub async fn connection_ping_closed_postgres() { |
| 105 | let ctx = std::rc::Rc::new(Box::new(TestContext::new("connection_ping_closed").await)); |
| 106 | let ctx_ping = std::rc::Rc::clone(&ctx); |
| 107 | |
| 108 | ctx.db.get_postgres_connection_pool().close().await; |
| 109 | assert_eq!( |
| 110 | ctx_ping.db.ping().await, |
| 111 | Err(DbErr::ConnectionAcquire(ConnAcquireErr::ConnectionClosed)) |
| 112 | ); |
| 113 | |
| 114 | let base_url = std::env::var("DATABASE_URL").unwrap(); |
| 115 | let mut opt = sea_orm::ConnectOptions::new(format!("{base_url}/connection_ping_closed")); |
| 116 | opt |
| 117 | // The connection pool has a single connection only |
| 118 | .max_connections(1) |
| 119 | // A controlled connection acquire timeout |
| 120 | .acquire_timeout(std::time::Duration::from_secs(2)); |
| 121 | |
| 122 | let db = sea_orm::Database::connect(opt).await.unwrap(); |
| 123 | |
| 124 | async fn transaction_blocked(db: &DatabaseConnection) { |
| 125 | let _txn = sea_orm::TransactionTrait::begin(db).await.unwrap(); |
| 126 | // Occupy the only connection, thus forcing others fail to acquire connection |
| 127 | tokio::time::sleep(std::time::Duration::from_secs(3)).await; |
| 128 | } |
| 129 | |
| 130 | async fn transaction(db: &DatabaseConnection) { |
| 131 | // Should fail to acquire |
| 132 | let txn = sea_orm::TransactionTrait::begin(db).await; |
| 133 | assert_eq!( |
| 134 | txn.expect_err("should be a time out"), |
| 135 | crate::DbErr::ConnectionAcquire(ConnAcquireErr::Timeout) |
| 136 | ) |
| 137 | } |
| 138 | |
| 139 | tokio::join!(transaction_blocked(&db), transaction(&db)); |
| 140 | |
| 141 | ctx.delete().await; |
| 142 | } |
| 143 | |
| 144 | #[sea_orm_macros::test] |
| 145 | #[cfg(feature = "sqlx-postgres")] |
nothing calls this directly
no test coverage detected