wasmcloud-test-util 0.19.0

Utilities for testing wasmCloud hosts, providers, and components.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use anyhow::{Context as _, Result};
use async_nats::{Client, ToServerAddrs};
use tokio::time::Duration;

/// Wait for a given NATS connection to be available
pub async fn wait_for_nats_connection(url: impl ToServerAddrs) -> Result<Client> {
    tokio::time::timeout(Duration::from_secs(3), async move {
        loop {
            if let Ok(c) = async_nats::connect(&url).await {
                return c;
            }
            tokio::time::sleep(Duration::from_millis(100)).await;
        }
    })
    .await
    .context("failed to connect NATS server client")
}