Skip to content

Commit

Permalink
Retry db connection
Browse files Browse the repository at this point in the history
  • Loading branch information
smrtrfszm committed Aug 9, 2024
1 parent e44cbda commit 5088f30
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions tests/utils/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,28 @@ async fn setup_database() -> (ContainerAsync<Postgres>, DbConn) {
container.get_host_port_ipv4(5432).await.unwrap(),
);

sleep(Duration::from_secs(1)).await;

tracing::debug!("Connecting to Postgres at {:?}", connection_string);

let db = Database::connect(connection_string)
.await
.inspect_err(|err| tracing::error!("postgres connect err: {err:?}"))
.unwrap();
let mut i = 0;
let db = loop {
let res = Database::connect(connection_string)
.await
.inspect_err(|err| tracing::error!("postgres connect err: {err:?}"));

match res {
Ok(db) => break db,
Err(_) => {
sleep(Duration::from_secs(1)).await;

if i > 3 {
tracing::error!("Can't connect to database");
panic!();
}

i += 1;
}
}
};

tracing::debug!("Running migrations");

Expand Down

0 comments on commit 5088f30

Please sign in to comment.