Test cleanup (#11192) (#11193)

Co-authored-by: Carl <carl@solana.com>
(cherry picked from commit c0dc21620b)

Co-authored-by: carllin <wumu727@gmail.com>
This commit is contained in:
mergify[bot]
2020-07-24 12:09:39 +00:00
committed by GitHub
parent c55a11d160
commit f9fd4bd24c

View File

@ -1948,18 +1948,23 @@ pub(crate) mod tests {
assert!(ReplayStage::is_partition_detected(&ancestors, 4, 3));
}
#[test]
fn test_child_slots_of_same_parent() {
struct ReplayBlockstoreComponents {
blockstore: Arc<Blockstore>,
validator_voting_keys: HashMap<Pubkey, Pubkey>,
progress: ProgressMap,
bank_forks: Arc<RwLock<BankForks>>,
leader_schedule_cache: Arc<LeaderScheduleCache>,
rpc_subscriptions: Arc<RpcSubscriptions>,
}
fn replay_blockstore_components() -> ReplayBlockstoreComponents {
// Setup blockstore
let ledger_path = get_tmp_ledger_path!();
{
// Setup
let blockstore = Arc::new(
Blockstore::open(&ledger_path)
.expect("Expected to be able to open database ledger"),
Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"),
);
let validator_authorized_voter_keypairs: Vec<_> = (0..20)
.map(|_| ValidatorVoteKeypairs::new(Keypair::new(), Keypair::new(), Keypair::new()))
.collect();
let validator_authorized_voter_keypairs: Vec<_> =
(0..20).map(|_| ValidatorVoteKeypairs::new_rand()).collect();
let validator_voting_keys: HashMap<_, _> = validator_authorized_voter_keypairs
.iter()
@ -1971,7 +1976,10 @@ pub(crate) mod tests {
&validator_authorized_voter_keypairs,
100,
);
let bank0 = Bank::new(&genesis_config);
// ProgressMap
let mut progress = ProgressMap::default();
progress.insert(
0,
@ -1984,14 +1992,48 @@ pub(crate) mod tests {
0,
),
);
// Leader schedule cache
let leader_schedule_cache = Arc::new(LeaderScheduleCache::new_from_bank(&bank0));
// BankForks
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank0)));
// RpcSubscriptions
let exit = Arc::new(AtomicBool::new(false));
let mut bank_forks = BankForks::new(bank0);
let rpc_subscriptions = Arc::new(RpcSubscriptions::new(
&exit,
bank_forks.clone(),
Arc::new(RwLock::new(BlockCommitmentCache::default_with_blockstore(
blockstore.clone(),
))),
));
ReplayBlockstoreComponents {
blockstore,
validator_voting_keys,
progress,
bank_forks,
leader_schedule_cache,
rpc_subscriptions,
}
}
#[test]
fn test_child_slots_of_same_parent() {
let ReplayBlockstoreComponents {
blockstore,
validator_voting_keys,
mut progress,
bank_forks,
leader_schedule_cache,
rpc_subscriptions,
} = replay_blockstore_components();
// Insert a non-root bank so that the propagation logic will update this
// bank
let bank1 = Bank::new_from_parent(
bank_forks.get(0).unwrap(),
bank_forks.read().unwrap().get(0).unwrap(),
&leader_schedule_cache.slot_leader_at(1, None).unwrap(),
1,
);
@ -2000,7 +2042,7 @@ pub(crate) mod tests {
ForkProgress::new_from_bank(
&bank1,
bank1.collector_id(),
&validator_voting_keys.get(&bank1.collector_id()).unwrap(),
validator_voting_keys.get(&bank1.collector_id()).unwrap(),
Some(0),
0,
0,
@ -2008,15 +2050,7 @@ pub(crate) mod tests {
);
assert!(progress.get_propagated_stats(1).unwrap().is_leader_slot);
bank1.freeze();
bank_forks.insert(bank1);
let bank_forks = Arc::new(RwLock::new(bank_forks));
let subscriptions = Arc::new(RpcSubscriptions::new(
&exit,
bank_forks.clone(),
Arc::new(RwLock::new(BlockCommitmentCache::default_with_blockstore(
blockstore.clone(),
))),
));
bank_forks.write().unwrap().insert(bank1);
// Insert shreds for slot NUM_CONSECUTIVE_LEADER_SLOTS,
// chaining to slot 1
@ -2031,7 +2065,7 @@ pub(crate) mod tests {
&blockstore,
&bank_forks,
&leader_schedule_cache,
&subscriptions,
&rpc_subscriptions,
None,
&mut progress,
&mut PubkeyReferences::default(),
@ -2055,7 +2089,7 @@ pub(crate) mod tests {
&blockstore,
&bank_forks,
&leader_schedule_cache,
&subscriptions,
&rpc_subscriptions,
None,
&mut progress,
&mut PubkeyReferences::default(),
@ -2071,7 +2105,7 @@ pub(crate) mod tests {
.get(2 * NUM_CONSECUTIVE_LEADER_SLOTS)
.is_some());
// // There are 20 equally staked acccounts, of which 3 have built
// // There are 20 equally staked accounts, of which 3 have built
// banks above or at bank 1. Because 3/20 < SUPERMINORITY_THRESHOLD,
// we should see 3 validators in bank 1's propagated_validator set.
let expected_leader_slots = vec![
@ -2089,7 +2123,6 @@ pub(crate) mod tests {
.contains(vote_key));
}
}
}
#[test]
fn test_handle_new_root() {
@ -2811,10 +2844,7 @@ pub(crate) mod tests {
&replay_votes_sender,
);
// No new stats should have been computed
assert!(replay_votes_receiver
.try_iter()
.collect::<Vec<_>>()
.is_empty());
assert!(replay_votes_receiver.try_iter().next().is_none());
assert!(newly_computed.is_empty());
}