diff --git a/src/startup.rs b/src/startup.rs index a0edf64..316f2e1 100644 --- a/src/startup.rs +++ b/src/startup.rs @@ -16,10 +16,7 @@ pub struct Application { impl Application { pub async fn build(configuration: Settings) -> Result { - let connection_pool = get_connection_pool(&configuration.database) - .await - .expect("Failed to connect to Postgres."); - + let connection_pool = get_connection_pool(&configuration.database); let sender_email = configuration .email_client .sender() @@ -52,11 +49,10 @@ impl Application { } } -pub async fn get_connection_pool(configuration: &DatabaseSettings) -> Result { +pub fn get_connection_pool(configuration: &DatabaseSettings) -> PgPool { PgPoolOptions::new() .connect_timeout(std::time::Duration::from_secs(2)) - .connect_with(configuration.with_db()) - .await + .connect_lazy_with(configuration.with_db()) } fn run( diff --git a/tests/api/helpers.rs b/tests/api/helpers.rs index 31e43f9..b0c49c1 100644 --- a/tests/api/helpers.rs +++ b/tests/api/helpers.rs @@ -60,9 +60,7 @@ pub async fn spawn_app() -> TestApp { TestApp { address, - db_pool: get_connection_pool(&configuration.database) - .await - .expect("Failed to connect to the database"), + db_pool: get_connection_pool(&configuration.database), } }