Skip to content

Commit

Permalink
test: Check the connectivity before doing IOs
Browse files Browse the repository at this point in the history
  • Loading branch information
akiradeveloper committed Jun 16, 2024
1 parent 3233783 commit 18d2b45
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ impl Env {
Ok(())
}

/// Wait for connection to be ready at most 5 seconds.
pub async fn check_connectivity(&self, id: u8) -> Result<()> {
for _ in 0..50 {
let uri: Uri = address_from_id(id).parse().unwrap();
let endpoint = Endpoint::from(uri)
.connect_timeout(std::time::Duration::from_secs(1));
match endpoint.connect().await {
Ok(_) => {
break;
}
Err(_) => {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}
}
}
Ok(())
}

pub async fn connect_ping_client(&self, id: u8) -> Result<testapp::PingClient<Channel>> {
let uri: Uri = address_from_id(id).parse().unwrap();
let endpoint = Endpoint::from(uri)
Expand Down
2 changes: 2 additions & 0 deletions tests/env/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async fn start_stop() -> Result<()> {
env.create(0, 1).await?;
env.start(0).await?;
env.connect_network(0).await?;
env.check_connectivity(0).await?;

let mut cli = env.connect_ping_client(0).await?;
cli.ping(()).await?;
Expand All @@ -40,6 +41,7 @@ async fn panic_loop() -> Result<()> {
env.create(0, 1).await?;
env.start(0).await?;
env.connect_network(0).await?;
env.check_connectivity(0).await?;

for i in 0..1000 {
dbg!(i);
Expand Down
1 change: 1 addition & 0 deletions tests/lol-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ impl Cluster {
env.create(id, n_lanes).await?;
env.start(id).await?;
env.connect_network(id).await?;
env.check_connectivity(id).await?;
}
Ok(Self { env })
}
Expand Down

0 comments on commit 18d2b45

Please sign in to comment.