Skip to content

Commit

Permalink
Further improve test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
SplittyDev committed Jul 24, 2023
1 parent 9ac6e65 commit 162c57a
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions node/narwhal/tests/bft_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,29 @@ async fn test_leader_election_consistency() {
let cloned_network = network.clone();
deadline!(Duration::from_secs(20), move || { cloned_network.is_round_reached(target_round) });

// Get all leaders
let leaders = network
.validators
.values()
// Get all validators in the network
let validators = network.validators.values().collect_vec();

// Get all validators in sync with the current round
let validators_for_round =
validators.iter().filter(|validator| validator.primary.current_round() == target_round).collect_vec();

// Get all leaders for the current round
let leaders = validators_for_round
.iter()
.flat_map(|v| v.bft.clone().map(|bft| bft.leader()))
.flatten()
.collect::<Vec<_>>();
println!("Found {} validators with a leader (out of {})", leaders.len(), network.validators.values().count());

println!(
"Found {} validators with a leader (out of {}, {} out of sync)",
leaders.len(),
validators_for_round.len(),
validators.len() - validators_for_round.len()
);

// Assert that we have N leaders
assert_eq!(leaders.len(), N as usize);
assert_eq!(leaders.len(), validators_for_round.len());

// Assert that all leaders are equal
assert!(leaders.iter().all_equal());
Expand Down

0 comments on commit 162c57a

Please sign in to comment.