Skip to content

Commit

Permalink
made the test_db_setup test less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Jul 20, 2024
1 parent 4d29cce commit b2bdf28
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions server/main-api/src/setup/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ impl MeiliSearchTestContainer {
#[tracing_test::traced_test]
async fn test_db_setup() {
let pg = PostgresTestContainer::new().await;
let res = crate::setup::database::load_data(&pg.pool).await;
match res {
Ok(()) => (), // sometimes connecting to the db fails... retrying this is realistic
Err(e) => {
error!("failed to load db because {e:?}. Retrying once");
tokio::time::sleep(Duration::from_secs(2)).await;
crate::setup::database::load_data(&pg.pool).await.unwrap()
for i in 0..20 {
let res = crate::setup::database::load_data(&pg.pool).await;
if let Err(e) = res {
error!("failed to load db because {e:?}. Retrying for 20s");
tokio::time::sleep(Duration::from_secs(1)).await;
} else {
info!("successfully initalised the db in try {i}");
break
}
}
}
Expand Down

0 comments on commit b2bdf28

Please sign in to comment.