From d4df73ed7289c581fd5d7f3fd9d3e2469b52e7e9 Mon Sep 17 00:00:00 2001 From: Victor Adossi Date: Fri, 4 Oct 2024 13:20:52 +0900 Subject: [PATCH] fix(tests): re-attempt connection to NATS Signed-off-by: Victor Adossi --- tests/e2e.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/e2e.rs b/tests/e2e.rs index 476c2418..7d83c9bf 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -94,10 +94,18 @@ impl ClientInfo { .kill_on_drop(true) .spawn() .expect("Unable to watch docker logs"); + // Connect to NATS - let client = async_nats::connect("127.0.0.1:4222") - .await - .expect("Unable to connect to nats"); + let client = tokio::time::timeout(Duration::from_secs(3), async { + loop { + if let Ok(client) = async_nats::connect("127.0.0.1:4222").await { + return client; + } + tokio::time::sleep(Duration::from_millis(250)).await; + } + }) + .await + .expect("timed out while creating NATS client"); ClientInfo { client,