Skip to content

Commit

Permalink
use get_storage_for_slot() in tests (#29517)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Jan 5, 2023
1 parent 8cdf5cd commit a140f06
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9547,6 +9547,10 @@ pub mod tests {
LoadZeroLamports::SomeWithZeroLamportAccountForTests,
)
}

fn get_storage_for_slot(&self, slot: Slot) -> Option<Arc<AccountStorageEntry>> {
self.storage.get_slot_storage_entry(slot)
}
}

/// This impl exists until this feature is activated:
Expand Down Expand Up @@ -17408,9 +17412,8 @@ pub mod tests {

// the append vec at max_slot_inclusive-1 should NOT have been removed since we created an ancient append vec there
assert!(is_ancient(
&db.get_storages_for_slot(max_slot_inclusive - 1)
.unwrap()
.first()
&db.storage
.get_slot_storage_entry(max_slot_inclusive - 1)
.unwrap()
.accounts
));
Expand All @@ -17430,16 +17433,14 @@ pub mod tests {

// 2 ancients and then missing (because combined into 2nd ancient)
assert!(is_ancient(
&db.get_storages_for_slot(ancient_slot)
.unwrap()
.first()
&db.storage
.get_slot_storage_entry(ancient_slot)
.unwrap()
.accounts
));
assert!(is_ancient(
&db.get_storages_for_slot(max_slot_inclusive - 1)
.unwrap()
.first()
&db.storage
.get_slot_storage_entry(max_slot_inclusive - 1)
.unwrap()
.accounts
));
Expand Down Expand Up @@ -17497,12 +17498,7 @@ pub mod tests {
// now, shrink the second ancient append vec into the first one
let mut current_ancient = CurrentAncientAppendVec::new(
ancient_slot,
Arc::clone(
db.get_storages_for_slot(ancient_slot)
.unwrap()
.first()
.unwrap(),
),
db.get_storage_for_slot(ancient_slot).unwrap(),
);
let mut dropped_roots = Vec::default();
db.combine_one_store_into_ancient(
Expand Down Expand Up @@ -17531,9 +17527,8 @@ pub mod tests {
// make sure there is only 1 ancient append vec at the ancient slot
assert_eq!(db.get_storages_for_slot(ancient_slot).unwrap().len(), 1);
assert!(is_ancient(
&db.get_storages_for_slot(ancient_slot)
.unwrap()
.first()
&db.storage
.get_slot_storage_entry(ancient_slot)
.unwrap()
.accounts
));
Expand All @@ -17557,7 +17552,7 @@ pub mod tests {
let max_slot_inclusive = ancient_slot + (num_normal_slots as Slot);

for slot in ancient_slot..=max_slot_inclusive {
originals.push(db.get_storages_for_slot(slot).unwrap());
originals.push(db.get_storage_for_slot(slot).unwrap());
}

{
Expand All @@ -17567,7 +17562,6 @@ pub mod tests {
if count_marked_dead >= dead_accounts {
break;
}
let original = original.first().unwrap();
let original = original.accounts.account_iter().next().unwrap();
let slot = ancient_slot + 1 + (count_marked_dead as Slot);
_ = db.purge_keys_exact(
Expand All @@ -17592,12 +17586,7 @@ pub mod tests {

// normal slots should have been appended to the ancient append vec in the first slot
assert_eq!(1, db.get_storages_for_slot(ancient_slot).unwrap().len());
let ancient = Arc::clone(
db.get_storages_for_slot(ancient_slot)
.unwrap()
.first()
.unwrap(),
);
let ancient = db.get_storage_for_slot(ancient_slot).unwrap();
assert!(is_ancient(&ancient.accounts));
for slot in (ancient_slot + 1)..=max_slot_inclusive {
assert!(db.get_storages_for_slot(slot).is_none());
Expand All @@ -17613,7 +17602,6 @@ pub mod tests {
"normal_slots: {num_normal_slots}, dead_accounts: {dead_accounts}"
);
for original in &originals {
let original = original.first().unwrap();
let original = original.accounts.account_iter().next().unwrap();

let i = after_stored_accounts
Expand Down Expand Up @@ -17727,7 +17715,7 @@ pub mod tests {

db.combine_ancient_slots(vec![slot1], CAN_RANDOMLY_SHRINK_FALSE);
assert_eq!(1, db.get_storages_for_slot(slot1).unwrap().len());
let ancient = Arc::clone(db.get_storages_for_slot(slot1).unwrap().first().unwrap());
let ancient = db.get_storage_for_slot(slot1).unwrap();
assert!(is_ancient(&ancient.accounts));
let after_stores = db.get_storages_for_slot(slot1).unwrap();
let GetUniqueAccountsResult {
Expand Down

0 comments on commit a140f06

Please sign in to comment.