pub async fn assert_stable_cluster(&self, expected_term: Option<u64>, expected_last_log: Option<u64>) {
        let isolated = self.isolated_nodes.read().await;
        let nodes = self.latest_metrics().await;

        let non_isolated_nodes: Vec<_> = nodes.iter().filter(|node| !isolated.contains(&node.id)).collect();
        let leader = nodes
            .iter()
            .filter(|node| !isolated.contains(&node.id))
            .find(|node| node.state == State::Leader)
            .expect("expected to find a cluster leader");
        let followers: Vec<_> = nodes
            .iter()
            .filter(|node| !isolated.contains(&node.id))
            .filter(|node| node.state == State::Follower)
            .collect();

        assert_eq!(
            followers.len() + 1,
            non_isolated_nodes.len(),
            "expected all nodes to be followers with one leader, got 1 leader and {} followers, expected {} followers",
            followers.len(),
            non_isolated_nodes.len() - 1,
        );
        let expected_term = match expected_term {
            Some(term) => term,
            None => leader.current_term,
        };
        let expected_last_log = match expected_last_log {
            Some(idx) => idx,
            None => leader.last_log_index,
        };
        let all_nodes = nodes.iter().map(|node| node.id).collect::<Vec<_>>();
        for node in non_isolated_nodes.iter() {
            assert_eq!(
                node.current_leader,
                Some(leader.id),
                "node {} has leader {:?}, expected {}",
                node.id,
                node.current_leader,
                leader.id
            );
            assert_eq!(
                node.current_term, expected_term,
                "node {} has term {}, expected {}",
                node.id, node.current_term, expected_term
            );
            assert_eq!(
                node.last_applied, expected_last_log,
                "node {} has last_applied {}, expected {}",
                node.id, node.last_applied, expected_last_log
            );
            assert_eq!(
                node.last_log_index, expected_last_log,
                "node {} has last_log_index {}, expected {}",
                node.id, node.last_log_index, expected_last_log
            );
            let mut members = node.membership_config.members.iter().cloned().collect::<Vec<_>>();
            members.sort_unstable();
            assert_eq!(
                members, all_nodes,
                "node {} has membership {:?}, expected {:?}",
                node.id, members, all_nodes
            );
            assert!(
                node.membership_config.members_after_consensus.is_none(),
                "node {} was not in uniform consensus state",
                node.id
            );
        }
    }
/// Assert that the cluster has an elected leader, and is in a stable state with all nodes uniform.
///
/// If `expected_term` is `Some`, then all nodes will be tested to ensure that they are in the
/// given term. Else, the leader's current term will be used for the assertion.
///
/// If `expected_last_log` is `Some`, then all nodes will be tested to ensure that their last
/// log index and last applied log match the given value. Else, the leader's last_log_index
/// will be used for the assertion.
Assert that the cluster has an elected leader, and is in a stable state with all nodes uniform.
If `expected_term` is `Some`, then all nodes will be tested to ensure that they are in the
given term. Else, the leader's current term will be used for the assertion.

If `expected_last_log` is `Some`, then all nodes will be tested to ensure that their last
log index and last applied log match the given value. Else, the leader's last_log_index
will be used for the assertion.
Assert that the cluster has an elected leader and is in a stable state with all nodes uniform . If ` expected_term ` is ` Some ` then all nodes will be tested to ensure that they are in the given term . Else the leader ' s current term will be used for the assertion . If ` expected_last_log ` is ` Some ` then all nodes will be tested to ensure that their last log index and last applied log match the given value . Else the leader ' s last_log_index will be used for the assertion .
pub async fn assert_stable_cluster(&self, expected_term: Option<u64>, expected_last_log: Option<u64>) {
        let isolated = self.isolated_nodes.read().await;
        let nodes = self.latest_metrics().await;
        let non_isolated_nodes: Vec<_> = nodes.iter().filter(|node| !isolated.contains(&node.id)).collect();
        let leader = nodes
            .iter()
            .filter(|node| !isolated.contains(&node.id))
            .find(|node| node.state == State::Leader)
            .expect("expected to find a cluster leader");
        let followers: Vec<_> = nodes
            .iter()
            .filter(|node| !isolated.contains(&node.id))
            .filter(|node| node.state == State::Follower)
            .collect();
        assert_eq!(
            followers.len() + 1,
            non_isolated_nodes.len(),
            "expected all nodes to be followers with one leader, got 1 leader and {} followers, expected {} followers",
            followers.len(),
            non_isolated_nodes.len() - 1,
        );
        let expected_term = match expected_term {
            Some(term) => term,
            None => leader.current_term,
        };
        let expected_last_log = match expected_last_log {
            Some(idx) => idx,
            None => leader.last_log_index,
        };
        let all_nodes = nodes.iter().map(|node| node.id).collect::<Vec<_>>();
        for node in non_isolated_nodes.iter() {
            assert_eq!(
                node.current_leader,
                Some(leader.id),
                "node {} has leader {:?}, expected {}",
                node.id,
                node.current_leader,
                leader.id
            );
            assert_eq!(
                node.current_term, expected_term,
                "node {} has term {}, expected {}",
                node.id, node.current_term, expected_term
            );
            assert_eq!(
                node.last_applied, expected_last_log,
                "node {} has last_applied {}, expected {}",
                node.id, node.last_applied, expected_last_log
            );
            assert_eq!(
                node.last_log_index, expected_last_log,
                "node {} has last_log_index {}, expected {}",
                node.id, node.last_log_index, expected_last_log
            );
            let mut members = node.membership_config.members.iter().cloned().collect::<Vec<_>>();
            members.sort_unstable();
            assert_eq!(
                members, all_nodes,
                "node {} has membership {:?}, expected {:?}",
                node.id, members, all_nodes
            );
            assert!(
                node.membership_config.members_after_consensus.is_none(),
                "node {} was not in uniform consensus state",
                node.id
            );
        }
    }
pub async fn assert_stable_cluster ( & self , expected_term : Option < u64 > , expected_last_log : Option < u64 > ) { let isolated = self . isolated_nodes . read ( ) . await ; let nodes = self . latest_metrics ( ) . await ; let non_isolated_nodes : Vec < _ > = nodes . iter ( ) . filter ( | node | ! isolated . contains ( & node . id ) ) . collect ( ) ; let leader = nodes . iter ( ) . filter ( | node | ! isolated . contains ( & node . id ) ) . find ( | node | node . state == State :: Leader ) . expect ( " " ) ; let followers : Vec < _ > = nodes . iter ( ) . filter ( | node | ! isolated . contains ( & node . id ) ) . filter ( | node | node . state == State :: Follower ) . collect ( ) ; assert_eq ! ( followers len ( ) 1 non_isolated_nodes len ( ) " " followers len ( ) non_isolated_nodes len ( ) 1 ) ; let expected_term = match expected_term { Some ( term ) => term , None => leader . current_term , } ; let expected_last_log = match expected_last_log { Some ( idx ) => idx , None => leader . last_log_index , } ; let all_nodes = nodes . iter ( ) . map ( | node | node . id ) . collect :: < Vec < _ > > ( ) ; for node in non_isolated_nodes . iter ( ) { assert_eq ! ( node current_leader Some ( leader id ) " " node id node current_leader leader id ) ; assert_eq ! ( node current_term expected_term " " node id node current_term expected_term ) ; assert_eq ! ( node last_applied expected_last_log " " node id node last_applied expected_last_log ) ; assert_eq ! ( node last_log_index expected_last_log " " node id node last_log_index expected_last_log ) ; let mut members = node . membership_config . members . iter ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ; members . sort_unstable ( ) ; assert_eq ! ( members all_nodes " " node id members all_nodes ) ; assert ! ( node membership_config members_after_consensus is_none ( ) " " node id ) ; } }
Assert that the cluster has an elected leader, and is in a stable state with all nodes uniform.
Assert that the cluster has an elected leader and is in a stable state with all nodes uniform .
&self
expected_term
Option<u64>
expected_last_log
Option<u64>
&self
expected_term
Option<u64>
expected_last_log
Option<u64>