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); 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") +}