diff --git a/tests/env/src/lib.rs b/tests/env/src/lib.rs index 43108dc0..2ea49ad6 100644 --- a/tests/env/src/lib.rs +++ b/tests/env/src/lib.rs @@ -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> { let uri: Uri = address_from_id(id).parse().unwrap(); let endpoint = Endpoint::from(uri) diff --git a/tests/env/tests/tests.rs b/tests/env/tests/tests.rs index 0f93c1b7..af45cfbf 100644 --- a/tests/env/tests/tests.rs +++ b/tests/env/tests/tests.rs @@ -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?; @@ -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); diff --git a/tests/lol-tests/src/lib.rs b/tests/lol-tests/src/lib.rs index bf2f7f5e..0e7a964c 100644 --- a/tests/lol-tests/src/lib.rs +++ b/tests/lol-tests/src/lib.rs @@ -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 }) }