From 0d6aace444c27dbd8abc9d0c5b485cd9663c8a58 Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Sat, 1 Jun 2024 08:06:48 +0200 Subject: [PATCH 1/2] Update misc_routes.rs --- agdb_server/tests/routes/misc_routes.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/agdb_server/tests/routes/misc_routes.rs b/agdb_server/tests/routes/misc_routes.rs index 2575e3c4..016110ec 100644 --- a/agdb_server/tests/routes/misc_routes.rs +++ b/agdb_server/tests/routes/misc_routes.rs @@ -1,3 +1,4 @@ +use crate::wait_for_ready; use crate::TestServer; use crate::TestServerImpl; use crate::ADMIN; @@ -86,6 +87,7 @@ async fn config_reuse() -> anyhow::Result<()> { server.process = Command::cargo_bin("agdb_server")? .current_dir(&server.dir) .spawn()?; + wait_for_ready(&client).await?; Ok(()) } @@ -111,6 +113,7 @@ async fn db_list_after_shutdown() -> anyhow::Result<()> { server.process = Command::cargo_bin("agdb_server")? .current_dir(&server.dir) .spawn()?; + wait_for_ready(&client).await?; client.user_login("userx", "userxpassword").await?; let dbs = client.db_list().await?.1; assert_eq!(dbs.len(), 1); @@ -142,6 +145,7 @@ async fn db_list_after_shutdown_corrupted_data() -> anyhow::Result<()> { server.process = Command::cargo_bin("agdb_server")? .current_dir(&server.dir) .spawn()?; + wait_for_ready(&client).await?; client.user_login("userx", "userxpassword").await?; let dbs = client.db_list().await?.1; assert_eq!(dbs.len(), 1); From 3dd3a4dba42d059a50d86b44ae146d5ce5902610 Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Sat, 1 Jun 2024 08:06:49 +0200 Subject: [PATCH 2/2] Update test_server.rs --- agdb_server/tests/test_server.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/agdb_server/tests/test_server.rs b/agdb_server/tests/test_server.rs index 340c9e8d..bc7d4222 100644 --- a/agdb_server/tests/test_server.rs +++ b/agdb_server/tests/test_server.rs @@ -222,3 +222,15 @@ impl Drop for TestServer { } } } + +pub async fn wait_for_ready(api: &AgdbApi) -> anyhow::Result<()> { + for _ in 0..RETRY_ATTEMPS { + if api.status().await.is_ok() { + return Ok(()); + } + + std::thread::sleep(RETRY_TIMEOUT); + } + + anyhow::bail!("Server not ready") +}