-
for context, I am working with an axum server and just running my test suite, which involves sending hundreds of requests which require the database. I am following the example specified in axum's repository (but switching bb8 for deadpool) and i have found the pool to deadlock in some cases, be flaky, and when it does work, be much slower than my previous sqlx and sea-orm rewrites of this program. is there something i'm fundamentally doing wrong? pool access/setuppub struct DatabaseConnection(pub Object<AsyncPgConnection>);
#[async_trait]
impl<S> FromRequestParts<S> for DatabaseConnection
where
S: Send + Sync,
Pool<AsyncPgConnection>: FromRef<S>,
{
type Rejection = ApiError;
#[tracing::instrument(skip(state), ret, err(Debug))]
async fn from_request_parts(
parts: &mut ::axum::http::request::Parts,
state: &S,
) -> ::std::result::Result<Self, Self::Rejection> {
let pool = Pool::from_ref(state);
let db = pool.get().await?;
Ok(Self(db))
}
} let manager = AsyncDieselConnectionManager::new(config.database_url.to_string());
let pool = Pool::builder(manager).max_size(90).build()?; integration test setup let mut database_url = assert_ok!(assert_ok!(env::var("DATABASE_URL")).parse::<Url>());
let database_name = Ulid::new().to_string();
database_url.set_path("postgres");
let mut db = assert_ok!(AsyncPgConnection::establish(database_url.as_str()).await);
assert_ok!(
sql_query(format!("CREATE DATABASE {:?}", database_name.as_str()))
.execute(&mut db)
.await
);
database_url.set_path(&database_name);
let config = Config {
socket: tcp_listener,
database_url,
jwt_secret: String::from_utf8_lossy(&rand::random::<[u8; 32]>()).into_owned(),
};
// api gets served (runs migrations, etc.) and the test makes http requests |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
update: i moved everything to |
Beta Was this translation helpful? Give feedback.
-
@vidhanio What difference do you see between deadpool and mobc or even bb8? Or do you see them as commodities? |
Beta Was this translation helpful? Give feedback.
Hi @lsunsi, I managed to find the source of most of my problems: I was running my tests in debug mode. Running
cargo test --release
fixed my issues with flaky tests on deadpool.