AcctIdx: create test fn get_test() to isolate changes to AcctIdx::get() (#21909)
This commit is contained in:
committed by
GitHub
parent
71b12b1f56
commit
02fa135815
@@ -2099,6 +2099,18 @@ pub mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IndexValue> AccountsIndex<T> {
|
||||
/// provides the ability to refactor this function on the api without bloody changes
|
||||
pub fn get_for_tests(
|
||||
&self,
|
||||
pubkey: &Pubkey,
|
||||
ancestors: Option<&Ancestors>,
|
||||
max_root: Option<Slot>,
|
||||
) -> AccountIndexGetResult<T> {
|
||||
self.get(pubkey, ancestors, max_root)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bitfield_delete_non_excess() {
|
||||
solana_logger::setup();
|
||||
@@ -2746,8 +2758,9 @@ pub mod tests {
|
||||
let key = Keypair::new();
|
||||
let index = AccountsIndex::<bool>::default_for_tests();
|
||||
let ancestors = Ancestors::default();
|
||||
assert!(index.get(&key.pubkey(), Some(&ancestors), None).is_none());
|
||||
assert!(index.get(&key.pubkey(), None, None).is_none());
|
||||
let key = &key.pubkey();
|
||||
assert!(index.get_for_tests(key, Some(&ancestors), None).is_none());
|
||||
assert!(index.get_for_tests(key, None, None).is_none());
|
||||
|
||||
let mut num = 0;
|
||||
index.unchecked_scan_accounts(
|
||||
@@ -2824,8 +2837,10 @@ pub mod tests {
|
||||
assert!(gc.is_empty());
|
||||
|
||||
let ancestors = Ancestors::default();
|
||||
assert!(index.get(&key.pubkey(), Some(&ancestors), None).is_none());
|
||||
assert!(index.get(&key.pubkey(), None, None).is_none());
|
||||
assert!(index
|
||||
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
|
||||
.is_none());
|
||||
assert!(index.get_for_tests(&key.pubkey(), None, None).is_none());
|
||||
|
||||
let mut num = 0;
|
||||
index.unchecked_scan_accounts(
|
||||
@@ -2863,8 +2878,10 @@ pub mod tests {
|
||||
index.insert_new_if_missing_into_primary_index(slot, items.len(), items.into_iter());
|
||||
|
||||
let mut ancestors = Ancestors::default();
|
||||
assert!(index.get(pubkey, Some(&ancestors), None).is_none());
|
||||
assert!(index.get(pubkey, None, None).is_none());
|
||||
assert!(index
|
||||
.get_for_tests(pubkey, Some(&ancestors), None)
|
||||
.is_none());
|
||||
assert!(index.get_for_tests(pubkey, None, None).is_none());
|
||||
|
||||
let mut num = 0;
|
||||
index.unchecked_scan_accounts(
|
||||
@@ -2875,7 +2892,9 @@ pub mod tests {
|
||||
);
|
||||
assert_eq!(num, 0);
|
||||
ancestors.insert(slot, 0);
|
||||
assert!(index.get(pubkey, Some(&ancestors), None).is_some());
|
||||
assert!(index
|
||||
.get_for_tests(pubkey, Some(&ancestors), None)
|
||||
.is_some());
|
||||
assert_eq!(index.ref_count_from_storage(pubkey), 1);
|
||||
index.unchecked_scan_accounts(
|
||||
"",
|
||||
@@ -2892,8 +2911,10 @@ pub mod tests {
|
||||
index.insert_new_if_missing_into_primary_index(slot, items.len(), items.into_iter());
|
||||
|
||||
let mut ancestors = Ancestors::default();
|
||||
assert!(index.get(pubkey, Some(&ancestors), None).is_none());
|
||||
assert!(index.get(pubkey, None, None).is_none());
|
||||
assert!(index
|
||||
.get_for_tests(pubkey, Some(&ancestors), None)
|
||||
.is_none());
|
||||
assert!(index.get_for_tests(pubkey, None, None).is_none());
|
||||
|
||||
let mut num = 0;
|
||||
index.unchecked_scan_accounts(
|
||||
@@ -2904,7 +2925,9 @@ pub mod tests {
|
||||
);
|
||||
assert_eq!(num, 0);
|
||||
ancestors.insert(slot, 0);
|
||||
assert!(index.get(pubkey, Some(&ancestors), None).is_some());
|
||||
assert!(index
|
||||
.get_for_tests(pubkey, Some(&ancestors), None)
|
||||
.is_some());
|
||||
assert_eq!(index.ref_count_from_storage(pubkey), 0); // cached, so 0
|
||||
index.unchecked_scan_accounts(
|
||||
"",
|
||||
@@ -3132,8 +3155,10 @@ pub mod tests {
|
||||
assert_eq!(1, account_maps_stats_len(&index));
|
||||
|
||||
let mut ancestors = Ancestors::default();
|
||||
assert!(index.get(&key.pubkey(), Some(&ancestors), None).is_none());
|
||||
assert!(index.get(&key.pubkey(), None, None).is_none());
|
||||
assert!(index
|
||||
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
|
||||
.is_none());
|
||||
assert!(index.get_for_tests(&key.pubkey(), None, None).is_none());
|
||||
|
||||
let mut num = 0;
|
||||
index.unchecked_scan_accounts(
|
||||
@@ -3144,7 +3169,9 @@ pub mod tests {
|
||||
);
|
||||
assert_eq!(num, 0);
|
||||
ancestors.insert(slot, 0);
|
||||
assert!(index.get(&key.pubkey(), Some(&ancestors), None).is_some());
|
||||
assert!(index
|
||||
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
|
||||
.is_some());
|
||||
index.unchecked_scan_accounts(
|
||||
"",
|
||||
&ancestors,
|
||||
@@ -3172,7 +3199,9 @@ pub mod tests {
|
||||
assert!(gc.is_empty());
|
||||
|
||||
let ancestors = vec![(1, 1)].into_iter().collect();
|
||||
assert!(index.get(&key.pubkey(), Some(&ancestors), None).is_none());
|
||||
assert!(index
|
||||
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
|
||||
.is_none());
|
||||
|
||||
let mut num = 0;
|
||||
index.unchecked_scan_accounts(
|
||||
@@ -3202,7 +3231,9 @@ pub mod tests {
|
||||
assert!(gc.is_empty());
|
||||
|
||||
let ancestors = vec![(0, 0)].into_iter().collect();
|
||||
let (list, idx) = index.get(&key.pubkey(), Some(&ancestors), None).unwrap();
|
||||
let (list, idx) = index
|
||||
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
|
||||
.unwrap();
|
||||
assert_eq!(list.slot_list()[idx], (0, true));
|
||||
|
||||
let mut num = 0;
|
||||
@@ -3427,7 +3458,7 @@ pub mod tests {
|
||||
assert!(gc.is_empty());
|
||||
|
||||
index.add_root(0, false);
|
||||
let (list, idx) = index.get(&key.pubkey(), None, None).unwrap();
|
||||
let (list, idx) = index.get_for_tests(&key.pubkey(), None, None).unwrap();
|
||||
assert_eq!(list.slot_list()[idx], (0, true));
|
||||
}
|
||||
|
||||
@@ -3540,7 +3571,9 @@ pub mod tests {
|
||||
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
||||
);
|
||||
assert!(gc.is_empty());
|
||||
let (list, idx) = index.get(&key.pubkey(), Some(&ancestors), None).unwrap();
|
||||
let (list, idx) = index
|
||||
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
|
||||
.unwrap();
|
||||
assert_eq!(list.slot_list()[idx], (0, true));
|
||||
drop(list);
|
||||
|
||||
@@ -3556,7 +3589,9 @@ pub mod tests {
|
||||
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
||||
);
|
||||
assert_eq!(gc, vec![(0, true)]);
|
||||
let (list, idx) = index.get(&key.pubkey(), Some(&ancestors), None).unwrap();
|
||||
let (list, idx) = index
|
||||
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
|
||||
.unwrap();
|
||||
assert_eq!(list.slot_list()[idx], (0, false));
|
||||
}
|
||||
|
||||
@@ -3589,10 +3624,14 @@ pub mod tests {
|
||||
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
||||
);
|
||||
assert!(gc.is_empty());
|
||||
let (list, idx) = index.get(&key.pubkey(), Some(&ancestors), None).unwrap();
|
||||
let (list, idx) = index
|
||||
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
|
||||
.unwrap();
|
||||
assert_eq!(list.slot_list()[idx], (0, true));
|
||||
let ancestors = vec![(1, 0)].into_iter().collect();
|
||||
let (list, idx) = index.get(&key.pubkey(), Some(&ancestors), None).unwrap();
|
||||
let (list, idx) = index
|
||||
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
|
||||
.unwrap();
|
||||
assert_eq!(list.slot_list()[idx], (1, false));
|
||||
}
|
||||
|
||||
@@ -3659,7 +3698,7 @@ pub mod tests {
|
||||
// Updating index should not purge older roots, only purges
|
||||
// previous updates within the same slot
|
||||
assert_eq!(gc, vec![]);
|
||||
let (list, idx) = index.get(&key.pubkey(), None, None).unwrap();
|
||||
let (list, idx) = index.get_for_tests(&key.pubkey(), None, None).unwrap();
|
||||
assert_eq!(list.slot_list()[idx], (3, true));
|
||||
|
||||
let mut num = 0;
|
||||
|
Reference in New Issue
Block a user