From b2bdf28e9aa8541e02ce5f15d89f0e8748e29129 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sat, 20 Jul 2024 23:51:53 +0200 Subject: [PATCH] made the `test_db_setup` test less flaky --- server/main-api/src/setup/tests.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/server/main-api/src/setup/tests.rs b/server/main-api/src/setup/tests.rs index 1869f1683..88bc0b83d 100644 --- a/server/main-api/src/setup/tests.rs +++ b/server/main-api/src/setup/tests.rs @@ -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 } } }