Skip to content

Commit

Permalink
Increase retries and add delay backoff to connect to client
Browse files Browse the repository at this point in the history
  • Loading branch information
lizardoluis committed Jul 4, 2024
1 parent cd87d5c commit 61bff98
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::process::{Child, Command};
use std::time::Duration;
use tokio::net::TcpListener;
use tonic::transport::Channel;
use tracing::warn;

mod clade;
mod cli;
Expand Down Expand Up @@ -99,7 +100,9 @@ pub async fn test_seafowl() -> TestSeafowl {
.expect("seafowl started");

// Try to connect to the client
let mut retries = 3;
let max_retries = 5;
let mut retries = 0;
let mut delay = Duration::from_millis(200);
loop {
match Channel::from_shared(format!("http://{flight_addr}"))
.expect("Endpoint created")
Expand All @@ -113,13 +116,23 @@ pub async fn test_seafowl() -> TestSeafowl {
proc: child,
}
}
Err(_err) if retries > 0 => {
retries -= 1;
tokio::time::sleep(Duration::from_millis(500)).await;
Err(err) if retries < max_retries => {
warn!(
"Connection attempt {}/{} to Seafowl failed: {}",
retries + 1,
max_retries,
err
);
tokio::time::sleep(delay).await;
retries += 1;
delay *= 2;
}
_ => {
Err(err) => {
let _ = child.kill();
panic!("Failed to connect to the test Seafowl")
panic!(
"Failed to connect to the test Seafowl after {} retries: {:?}",
retries, err
);
}
}
}
Expand Down

0 comments on commit 61bff98

Please sign in to comment.