async fn wait_for_admin_to_be_available(client: &eventstore::Client) -> eventstore::Result<()> {
    fn can_retry(e: &eventstore::Error) -> bool {
        match e {
            eventstore::Error::AccessDenied
            | eventstore::Error::DeadlineExceeded
            | eventstore::Error::ServerError(_)
            | eventstore::Error::ResourceNotFound => true,
            _ => false,
        }
    }
    let mut count = 0;

    while count < 50 {
        count += 1;

        debug!("Checking if admin user is available...{}/50", count);
        let result = tokio::time::timeout(
            std::time::Duration::from_secs(1),
            client.read_stream("$users", &Default::default(), Single),
        )
        .await;

        match result {
            Err(_) => {
                debug!("Request timed out, retrying...");
                tokio::time::sleep(Duration::from_millis(500)).await;
            }

            Ok(result) => match result.and_then(|r| r) {
                Err(e) if can_retry(&e) => {
                    debug!("Not available: {:?}, retrying...", e);
                    tokio::time::sleep(Duration::from_millis(500)).await;
                }

                Err(e) => {
                    debug!("Fatal error, stop retrying. Cause: {:?}", e);
                    return Err(e);
                }

                Ok(opt) => {
                    if opt.is_some() {
                        debug!("Admin account is available!");
                        return Ok(());
                    }

                    debug!("$users stream seems to be empty, retrying...");
                    tokio::time::sleep(Duration::from_millis(500)).await;
                }
            },
        }
    }

    Err(eventstore::Error::ServerError(
        "Waiting for the admin user to be created took too much time".to_string(),
    ))
}
// This function assumes that we are using the admin credentials. It's possible during CI that
// the cluster hasn't created the admin user yet, leading to failing the tests.
This function assumes that we are using the admin credentials. It's possible during CI that
the cluster hasn't created the admin user yet, leading to failing the tests.
This function assumes that we are using the admin credentials . It ' s possible during CI that the cluster hasn ' t created the admin user yet leading to failing the tests .
async fn wait_for_admin_to_be_available(client: &eventstore::Client) -> eventstore::Result<()> {
    fn can_retry(e: &eventstore::Error) -> bool {
        match e {
            eventstore::Error::AccessDenied
            | eventstore::Error::DeadlineExceeded
            | eventstore::Error::ServerError(_)
            | eventstore::Error::ResourceNotFound => true,
            _ => false,
        }
    }
    let mut count = 0;
    while count < 50 {
        count += 1;
        debug!("Checking if admin user is available...{}/50", count);
        let result = tokio::time::timeout(
            std::time::Duration::from_secs(1),
            client.read_stream("$users", &Default::default(), Single),
        )
        .await;
        match result {
            Err(_) => {
                debug!("Request timed out, retrying...");
                tokio::time::sleep(Duration::from_millis(500)).await;
            }
            Ok(result) => match result.and_then(|r| r) {
                Err(e) if can_retry(&e) => {
                    debug!("Not available: {:?}, retrying...", e);
                    tokio::time::sleep(Duration::from_millis(500)).await;
                }
                Err(e) => {
                    debug!("Fatal error, stop retrying. Cause: {:?}", e);
                    return Err(e);
                }
                Ok(opt) => {
                    if opt.is_some() {
                        debug!("Admin account is available!");
                        return Ok(());
                    }
                    debug!("$users stream seems to be empty, retrying...");
                    tokio::time::sleep(Duration::from_millis(500)).await;
                }
            },
        }
    }
    Err(eventstore::Error::ServerError(
        "Waiting for the admin user to be created took too much time".to_string(),
    ))
}
async fn wait_for_admin_to_be_available ( client : & eventstore :: Client ) -> eventstore :: Result < ( ) > { fn can_retry ( e : & eventstore :: Error ) -> bool { match e { eventstore :: Error :: AccessDenied | eventstore :: Error :: DeadlineExceeded | eventstore :: Error :: ServerError ( _ ) | eventstore :: Error :: ResourceNotFound => true , _ => false , } } let mut count = 0 ; while count < 50 { count += 1 ; debug ! ( " " count ) ; let result = tokio :: time :: timeout ( std :: time :: Duration :: from_secs ( 1 ) , client . read_stream ( " " , & Default :: default ( ) , Single ) , ) . await ; match result { Err ( _ ) => { debug ! ( " " ) ; tokio :: time :: sleep ( Duration :: from_millis ( 500 ) ) . await ; } Ok ( result ) => match result . and_then ( | r | r ) { Err ( e ) if can_retry ( & e ) => { debug ! ( " " e ) ; tokio :: time :: sleep ( Duration :: from_millis ( 500 ) ) . await ; } Err ( e ) => { debug ! ( " " e ) ; return Err ( e ) ; } Ok ( opt ) => { if opt . is_some ( ) { debug ! ( " " ) ; return Ok ( ( ) ) ; } debug ! ( " " ) ; tokio :: time :: sleep ( Duration :: from_millis ( 500 ) ) . await ; } } , } } Err ( eventstore :: Error :: ServerError ( " " . to_string ( ) , ) ) }
This function assumes that we are using the admin credentials.
This function assumes that we are using the admin credentials .
client
&eventstore::Client
client
&eventstore::Client