/// Detect whether a replica's status becomes acceptable within `timeout`.
///
/// # Arguments
///
/// * `ctx`                  - Fondue context
/// * `endpoint`             - Endpoint of a subnet
/// * `retry_delay`          - Duration between polling attempts
/// * `timeout`              - Duration after which we give up (returning false)
/// * `acceptance_criterium` - Predicate determining whether the current status
///   is accepted
///
/// Eventually returns whether the replica status has changed as specified via
/// `acceptance_criterium`.
Detect whether a replica's status becomes acceptable within `timeout`.
Detect whether a replica ' s status becomes acceptable within ` timeout ` .
pub async fn await_replica_status_change(
    ctx: &ic_fondue::pot::Context,
    endpoint: &IcEndpoint,
    retry_delay: Duration,
    timeout: Duration,
    acceptance_criterium: impl Fn(&ic_agent::agent::status::Status) -> bool,
) -> bool {
    let start_time = std::time::Instant::now();
    let mut i = 0usize;
    loop {
        i += 1;
        info!(
            ctx.logger,
            "Attempt #{} of detecting replica status change", i
        );
        let status = get_replica_status(endpoint)
            .await
            .expect("Could not obtain new agent status");
        if acceptance_criterium(&status) {
            info!(
                ctx.logger,
                " status change has been accepted.\nNew status:\n{:?}", status
            );
            return true;
        }
        if std::time::Instant::now()
            .duration_since(start_time)
            .gt(&timeout)
        {
            // Give up
            info!(
                ctx.logger,
                " did not detect status change within {:?}.\nStatus remains:\n{:?}",
                timeout,
                status
            );
            return false;
        } else {
            // Continue polling with delay
            sleep(retry_delay).await;
        }
    }
}
pub async fn await_replica_status_change ( ctx : & ic_fondue :: pot :: Context , endpoint : & IcEndpoint , retry_delay : Duration , timeout : Duration , acceptance_criterium : impl Fn ( & ic_agent :: agent :: status :: Status ) -> bool , ) -> bool { let start_time = std :: time :: Instant :: now ( ) ; let mut i = 0usize ; loop { i += 1 ; info ! ( ctx logger " " i ) ; let status = get_replica_status ( endpoint ) . await . expect ( " " ) ; if acceptance_criterium ( & status ) { info ! ( ctx logger " \n \n " status ) ; return true ; } if std :: time :: Instant :: now ( ) . duration_since ( start_time ) . gt ( & timeout ) { // Give up info ! ( ctx logger " \n \n " timeout status ) ; return false ; } else { // Continue polling with delay sleep ( retry_delay ) . await ; } } }
Detect whether a replica's status becomes acceptable within `timeout`.
Detect whether a replica ' s status becomes acceptable within ` timeout ` .
ctx
&ic_fondue::pot::Context
endpoint
&IcEndpoint
retry_delay
Duration
timeout
Duration
acceptance_criterium
impl Fn(&ic_agent::agent::status::Status) -> bool