Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] Add missing wait in test server after shutdown #1107 #1108

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions agdb_server/tests/routes/misc_routes.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::wait_for_ready;
use crate::TestServer;
use crate::TestServerImpl;
use crate::ADMIN;
Expand Down Expand Up @@ -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(())
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions agdb_server/tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,15 @@ impl Drop for TestServer {
}
}
}

pub async fn wait_for_ready(api: &AgdbApi<ReqwestClient>) -> 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")
}