remove sleeps from repair tests (#30252)

This commit is contained in:
Jeff Biseda 2023-02-13 10:28:30 -08:00 committed by GitHub
parent 2decc5275c
commit f4fe550004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 14 deletions

View File

@ -4,7 +4,7 @@ use {
serve_repair::ShredRepairType, tree_diff::TreeDiff,
},
solana_ledger::{blockstore::Blockstore, blockstore_meta::SlotMeta},
solana_sdk::{clock::Slot, hash::Hash, timing::timestamp},
solana_sdk::{clock::Slot, hash::Hash},
std::collections::{HashMap, HashSet},
};
@ -114,6 +114,7 @@ pub fn get_closest_completion(
slot_meta_cache: &mut HashMap<Slot, Option<SlotMeta>>,
processed_slots: &mut HashSet<Slot>,
limit: usize,
now_timestamp: u64,
) -> Vec<ShredRepairType> {
let mut v: Vec<(Slot, u64)> = Vec::default();
let iter = GenericTraversal::new(tree);
@ -187,7 +188,7 @@ pub fn get_closest_completion(
slot,
slot_meta,
limit - repairs.len(),
timestamp(),
now_timestamp,
);
repairs.extend(new_repairs);
}
@ -200,10 +201,9 @@ pub fn get_closest_completion(
pub mod test {
use {
super::*,
crate::repair_service::DEFER_REPAIR_THRESHOLD,
crate::repair_service::post_shred_deferment_timestamp,
solana_ledger::{blockstore::Blockstore, get_tmp_ledger_path},
solana_sdk::hash::Hash,
std::thread::sleep,
solana_sdk::{hash::Hash, timing::timestamp},
trees::{tr, Tree, TreeWalk},
};
@ -240,6 +240,7 @@ pub mod test {
&mut slot_meta_cache,
&mut processed_slots,
10,
timestamp(),
);
assert_eq!(repairs, []);
@ -255,7 +256,6 @@ pub mod test {
Hash::default(),
);
let heaviest_subtree_fork_choice = HeaviestSubtreeForkChoice::new_from_tree(forks);
sleep(DEFER_REPAIR_THRESHOLD);
let mut slot_meta_cache = HashMap::default();
let mut processed_slots = HashSet::default();
let repairs = get_closest_completion(
@ -264,6 +264,7 @@ pub mod test {
&mut slot_meta_cache,
&mut processed_slots,
2,
post_shred_deferment_timestamp(),
);
assert_eq!(
repairs,

View File

@ -44,7 +44,7 @@ use {
use {solana_ledger::shred::Nonce, solana_sdk::clock::DEFAULT_MS_PER_SLOT};
// Time to defer repair requests to allow for turbine propagation
pub(crate) const DEFER_REPAIR_THRESHOLD: Duration = Duration::from_millis(200);
const DEFER_REPAIR_THRESHOLD: Duration = Duration::from_millis(200);
const DEFER_REPAIR_THRESHOLD_TICKS: u64 = DEFER_REPAIR_THRESHOLD.as_millis() as u64 / MS_PER_TICK;
pub type DuplicateSlotsResetSender = CrossbeamSender<Vec<(Slot, Hash)>>;
@ -609,6 +609,7 @@ impl RepairService {
blockstore: &Blockstore,
max_repairs: usize,
repair_range: &RepairSlotRange,
now_timestamp: u64,
) -> crate::result::Result<Vec<ShredRepairType>> {
// Slot height and shred indexes for shreds we want to repair
let mut repairs: Vec<ShredRepairType> = vec![];
@ -630,7 +631,7 @@ impl RepairService {
slot,
&meta,
max_repairs - repairs.len(),
timestamp(),
now_timestamp,
);
repairs.extend(new_repairs);
}
@ -929,8 +930,6 @@ mod test {
blockstore
.insert_shreds(shreds_to_write, None, false)
.unwrap();
// sleep so that the holes are ready for repair
sleep(Duration::from_secs(1));
let expected: Vec<ShredRepairType> = (0..num_slots)
.flat_map(|slot| {
missing_indexes_per_slot
@ -950,7 +949,7 @@ mod test {
MAX_UNKNOWN_LAST_INDEX_REPAIRS,
MAX_CLOSEST_COMPLETION_REPAIRS,
&HashSet::default(),
timestamp(),
post_shred_deferment_timestamp(),
&mut RepairTiming::default(),
&mut BestRepairsStats::default(),
),
@ -967,7 +966,7 @@ mod test {
MAX_UNKNOWN_LAST_INDEX_REPAIRS,
MAX_CLOSEST_COMPLETION_REPAIRS,
&HashSet::default(),
timestamp(),
post_shred_deferment_timestamp(),
&mut RepairTiming::default(),
&mut BestRepairsStats::default(),
)[..],
@ -1038,8 +1037,7 @@ mod test {
slot_shreds.remove(0);
blockstore.insert_shreds(slot_shreds, None, false).unwrap();
}
// sleep to make slot eligible for repair
sleep(Duration::from_secs(1));
// Iterate through all possible combinations of start..end (inclusive on both
// sides of the range)
for start in 0..slots.len() {
@ -1064,6 +1062,7 @@ mod test {
&blockstore,
std::usize::MAX,
&repair_slot_range,
post_shred_deferment_timestamp(),
)
.unwrap(),
expected
@ -1112,6 +1111,7 @@ mod test {
&blockstore,
std::usize::MAX,
&repair_slot_range,
timestamp(),
)
.unwrap(),
expected

View File

@ -223,6 +223,7 @@ impl RepairWeight {
&mut slot_meta_cache,
&mut processed_slots,
max_closest_completion_repairs,
now_timestamp,
);
let num_closest_completion_repairs = closest_completion_repairs.len();
let num_closest_completion_slots = processed_slots.len() - pre_num_slots;
@ -471,6 +472,7 @@ impl RepairWeight {
slot_meta_cache: &mut HashMap<Slot, Option<SlotMeta>>,
processed_slots: &mut HashSet<Slot>,
max_new_repairs: usize,
now_timestamp: u64,
) -> Vec<ShredRepairType> {
let mut repairs = Vec::default();
for (_slot, tree) in self.trees.iter() {
@ -483,6 +485,7 @@ impl RepairWeight {
slot_meta_cache,
processed_slots,
max_new_repairs - repairs.len(),
now_timestamp,
);
repairs.extend(new_repairs);
}