Skip to content

Commit

Permalink
Wait for server to be available and ready before performing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasPius committed Apr 9, 2024
1 parent 27325cc commit e578ee4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;
use hrobot::{
api::{
firewall::State,
server::{Server, ServerId},
server::{self, Server, ServerId},
storagebox::{StorageBox, StorageBoxId},
vswitch::{ConnectionStatus, VSwitch, VSwitchId},
},
Expand All @@ -19,10 +19,17 @@ pub const PROVISIONED_SERVER_ID_PATH: &str = "provisioned-server";
#[allow(unused)]
pub async fn provisioned_server_id() -> ServerId {
dotenvy::dotenv().ok();
let robot = AsyncRobot::default();

for i in 0..60 {
if let Ok(contents) = std::fs::read_to_string(PROVISIONED_SERVER_ID_PATH) {
return ServerId(u32::from_str_radix(&contents, 10).unwrap());
let server_id = ServerId(u32::from_str_radix(&contents, 10).unwrap());

if let Ok(server) = robot.get_server(server_id).await {
if server.status == server::Status::Ready {
return server_id;
}
}
}

tokio::time::sleep(Duration::from_secs(30)).await;
Expand Down

0 comments on commit e578ee4

Please sign in to comment.