Skip to content

Commit

Permalink
Update unit tests across the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
steviez committed Mar 25, 2024
1 parent fe26ee3 commit a7ef7da
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ mod tests {
crate::banking_trace::{BankingPacketBatch, BankingTracer},
crossbeam_channel::{unbounded, Receiver},
itertools::Itertools,
solana_entry::entry::{Entry, EntrySlice},
solana_entry::entry::{entry_thread_pool_for_tests, Entry, EntrySlice},
solana_gossip::cluster_info::Node,
solana_ledger::{
blockstore::Blockstore,
Expand Down Expand Up @@ -941,7 +941,7 @@ mod tests {
.collect();
trace!("done");
assert_eq!(entries.len(), genesis_config.ticks_per_slot as usize);
assert!(entries.verify(&start_hash));
assert!(entries.verify(&start_hash, &entry_thread_pool_for_tests()));
assert_eq!(entries[entries.len() - 1].hash, bank.last_blockhash());
banking_stage.join().unwrap();
}
Expand Down Expand Up @@ -1060,7 +1060,7 @@ mod tests {
.map(|(_bank, (entry, _tick_height))| entry)
.collect();

assert!(entries.verify(&blockhash));
assert!(entries.verify(&blockhash, &entry_thread_pool_for_tests()));
if !entries.is_empty() {
blockhash = entries.last().unwrap().hash;
for entry in entries {
Expand Down
1 change: 0 additions & 1 deletion entry/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,6 @@ pub fn next_versioned_entry(
}
}

#[cfg(test)]
pub fn entry_thread_pool_for_tests() -> ThreadPool {
rayon::ThreadPoolBuilder::new()
.num_threads(4)
Expand Down
14 changes: 9 additions & 5 deletions local-cluster/src/cluster_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use log::*;
use {
rand::{thread_rng, Rng},
rayon::prelude::*,
rayon::{prelude::*, ThreadPool},
solana_client::{
connection_cache::{ConnectionCache, Protocol},
thin_client::ThinClient,
},
solana_core::consensus::VOTE_THRESHOLD_DEPTH,
solana_entry::entry::{Entry, EntrySlice},
solana_entry::entry::{self, Entry, EntrySlice},
solana_gossip::{
cluster_info::{self, ClusterInfo},
contact_info::{ContactInfo, LegacyContactInfo},
Expand Down Expand Up @@ -177,6 +177,8 @@ pub fn send_many_transactions(

pub fn verify_ledger_ticks(ledger_path: &Path, ticks_per_slot: usize) {
let ledger = Blockstore::open(ledger_path).unwrap();
let thread_pool = entry::entry_thread_pool_for_tests();

let zeroth_slot = ledger.get_slot_entries(0, 0).unwrap();
let last_id = zeroth_slot.last().unwrap().hash;
let next_slots = ledger.get_slots_since(&[0]).unwrap().remove(&0).unwrap();
Expand All @@ -198,7 +200,7 @@ pub fn verify_ledger_ticks(ledger_path: &Path, ticks_per_slot: usize) {
None
};

let last_id = verify_slot_ticks(&ledger, slot, &last_id, should_verify_ticks);
let last_id = verify_slot_ticks(&ledger, &thread_pool, slot, &last_id, should_verify_ticks);
pending_slots.extend(
next_slots
.into_iter()
Expand Down Expand Up @@ -580,21 +582,23 @@ pub fn start_gossip_voter(

fn get_and_verify_slot_entries(
blockstore: &Blockstore,
thread_pool: &ThreadPool,
slot: Slot,
last_entry: &Hash,
) -> Vec<Entry> {
let entries = blockstore.get_slot_entries(slot, 0).unwrap();
assert!(entries.verify(last_entry));
assert!(entries.verify(last_entry, thread_pool));
entries
}

fn verify_slot_ticks(
blockstore: &Blockstore,
thread_pool: &ThreadPool,
slot: Slot,
last_entry: &Hash,
expected_num_ticks: Option<usize>,
) -> Hash {
let entries = get_and_verify_slot_entries(blockstore, slot, last_entry);
let entries = get_and_verify_slot_entries(blockstore, thread_pool, slot, last_entry);
let num_ticks: usize = entries.iter().map(|entry| entry.is_tick() as usize).sum();
if let Some(expected_num_ticks) = expected_num_ticks {
assert_eq!(num_ticks, expected_num_ticks);
Expand Down

0 comments on commit a7ef7da

Please sign in to comment.