Skip to content

Fail to get the connection with the features ["postgres", "bb8"] #99

Closed as not planned
@iamnivekx

Description

@iamnivekx

Setup

Versions

  • Rust: rustc 1.72.0
  • Diesel: 2.1.0
  • Diesel_async: 0.3.1
  • Database: postgres
  • Operating System macos 13.4.1

Feature Flags

  • diesel: ["postgres", "r2d2"]
  • diesel_async: ["postgres", "bb8"]

Problem Description

Fail to get the connection, TimedOut

What are you trying to accomplish?

Manager the connection with the diesel-async

What is the expected output?

What is the actual output?

thread 'pg_async::tests::test_init_db' panicked at 'could not get connection: TimedOut', crates/srv-storage/src/pg_async.rs:39:41
stack backtrace:
   0: rust_begin_unwind
             at /rustc/065a1f5df9c2f1d93269e4d25a2acabbddb0db8d/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/065a1f5df9c2f1d93269e4d25a2acabbddb0db8d/library/core/src/panicking.rs:67:14
   2: core::result::unwrap_failed
             at /rustc/065a1f5df9c2f1d93269e4d25a2acabbddb0db8d/library/core/src/result.rs:1651:5
   3: core::result::Result<T,E>::expect
             at /rustc/065a1f5df9c2f1d93269e4d25a2acabbddb0db8d/library/core/src/result.rs:1033:23
   4: srv_storage::pg_async::tests::test_init_db::{{closure}}
             at ./src/pg_async.rs:39:24

Are you seeing any additional errors?

No additional error is shown.

Steps to reproduce

use diesel_async::{
    pooled_connection::{bb8::Pool, bb8::PooledConnection, AsyncDieselConnectionManager},
    AsyncPgConnection,
};

pub type DbConnectionManger = AsyncDieselConnectionManager<AsyncPgConnection>;

pub type DbPool = Pool<AsyncPgConnection>;

pub type DbConnection<'a> = PooledConnection<'a, AsyncDieselConnectionManager<AsyncPgConnection>>;

#[tracing::instrument()]
pub async fn init_db(database_url: &str) -> DbPool {
    let mgr = AsyncDieselConnectionManager::<AsyncPgConnection>::new(database_url);

    Pool::builder()
        .build(mgr)
        .await
        .expect("could not build connection pool")
}

#[cfg(test)]
mod tests {
    use super::init_db;
    use diesel::{prelude::*, sql_query, sql_types::Text};
    use diesel_async::RunQueryDsl;
    #[derive(QueryableByName)]
    struct SqlVersion {
        #[diesel(sql_type = Text)]
        pub version: String,
    }

    #[tokio::main]
    #[test]
    async fn test_init_db() {
        dotenvy::dotenv().ok();
        let database_url = std::env::var("DATABASE_URL").expect("Expected DATABASE_URL to be set");
        let pool = init_db(database_url.as_str()).await;
        let mut conn = pool.get().await.expect("could not get connection");
        let version = sql_query("SELECT version()")
            .get_result::<SqlVersion>(&mut conn)
            .await;

        assert!(version.is_ok());
        let version = version.unwrap();
        println!("database version {}", version.version);
    }
}
diesel = { version = "2.1.0", features = ["postgres", "r2d2"] }
diesel-async = { version = "0.3.1", features = ["postgres", "bb8"] }

Checklist

  • I have already looked over the issue tracker for similar possible closed issues.
  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
  • This issue can be reproduced without requiring a third party crate

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions