Skip to content

Commit 4b7400d

Browse files
committed
fix(e2e-tests): Deal with intermittent e2e test failures
The e2e tests now start the `ark-client` by attempting to connect to the Ark server more than once, in case the Ark server is not ready straight away.
1 parent 3397fa3 commit 4b7400d

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

ark-client/src/lib.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::error::ErrorContext;
2+
use crate::utils::sleep;
23
use crate::utils::timeout_op;
34
use crate::wallet::BoardingWallet;
45
use crate::wallet::OnchainWallet;
@@ -343,6 +344,50 @@ where
343344
server_info,
344345
})
345346
}
347+
348+
/// Connects to the Ark server and retrieves server information.
349+
///
350+
/// If it encounters errors, it will retry `max_retries`.
351+
///
352+
/// # Errors
353+
///
354+
/// Returns an error if the connection fails or times out.
355+
pub async fn connect_with_retries(mut self, max_retries: usize) -> Result<Client<B, W>, Error> {
356+
let mut n_retries = 0;
357+
while n_retries < max_retries {
358+
let res = timeout_op(self.timeout, self.network_client.connect())
359+
.await
360+
.context("Failed to connect to Ark server")?;
361+
362+
match res {
363+
Ok(()) => break,
364+
Err(error) => {
365+
tracing::warn!(?error, "Failed to connect to Ark server, retrying");
366+
367+
sleep(Duration::from_secs(2)).await;
368+
369+
n_retries += 1;
370+
371+
continue;
372+
}
373+
};
374+
}
375+
376+
let server_info = timeout_op(self.timeout, self.network_client.get_info())
377+
.await
378+
.context("Failed to get Ark server info")??;
379+
380+
tracing::debug!(
381+
name = self.name,
382+
ark_server_url = ?self.network_client,
383+
"Connected to Ark server"
384+
);
385+
386+
Ok(Client {
387+
inner: self,
388+
server_info,
389+
})
390+
}
346391
}
347392

348393
impl<B, W> Client<B, W>

e2e-tests/tests/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ pub async fn set_up_client(
369369
"http://localhost:7070".to_string(),
370370
Duration::from_secs(30),
371371
)
372-
.connect()
372+
.connect_with_retries(5)
373373
.await
374374
.unwrap();
375375

0 commit comments

Comments
 (0)