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

Allow for retries when checking if the emulator is running #1459

Merged
merged 3 commits into from
Jul 16, 2024
Merged
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
48 changes: 35 additions & 13 deletions cmd/crates/stellar-ledger/tests/test/emulator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,30 +343,52 @@ fn get_http_transport(host: &str, port: u16) -> Result<impl Exchange, Error> {
}

async fn wait_for_emulator_start_text(ui_host_port: u16) {
sleep(Duration::from_secs(1)).await;

let mut ready = false;
while !ready {
let events = get_emulator_events(ui_host_port).await;
let events = get_emulator_events_with_retries(ui_host_port, 5).await;

if events.iter().any(|event| event.text == "is ready") {
ready = true;
}
sleep(Duration::from_secs(1)).await;
}
}

async fn get_emulator_events(ui_host_port: u16) -> Vec<EmulatorEvent> {
// Allowing for less retries here because presumably the emulator should be up and running since we waited
// for the "is ready" text via wait_for_emulator_start_text
get_emulator_events_with_retries(ui_host_port, 1).await
}

async fn get_emulator_events_with_retries(
ui_host_port: u16,
max_retries: u16,
) -> Vec<EmulatorEvent> {
let client = reqwest::Client::new();
let resp = client
.get(format!("http://localhost:{ui_host_port}/events"))
.send()
.await
.unwrap()
.json::<EventsResponse>()
.await
.unwrap();
resp.events
let mut retries = 0;

let mut wait_time = Duration::from_secs(1);

loop {
match client
.get(format!("http://localhost:{ui_host_port}/events"))
.send()
.await
{
Ok(req) => {
let resp = req.json::<EventsResponse>().await.unwrap();
return resp.events;
}
Err(e) => {
println!("this many retries: {retries}");
retries += 1;
if retries >= max_retries {
panic!("Failed to get emulator events: {e}");
}
sleep(wait_time).await;
wait_time *= 2;
}
}
}
}

async fn approve_tx_hash_signature(ui_host_port: u16, device_model: String) {
Expand Down
Loading