Skip to content

Commit

Permalink
add test method get_and_assert_single_storage
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Jan 3, 2023
1 parent 71ba409 commit 337b4fe
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14600,6 +14600,18 @@ pub mod tests {
.is_none());
}

impl AccountsDb {
fn get_and_assert_single_storage(&self, slot: Slot) -> Arc<AccountStorageEntry> {
let mut storage_maps: SnapshotStorage = self
.storage
.get_slot_storage_entries(slot)
.unwrap_or_default();

assert_eq!(storage_maps.len(), 1);
self.storage.get_slot_storage_entry(slot).unwrap()
}
}

#[test]
fn test_alive_bytes() {
let accounts_db = AccountsDb::new_with_config_for_tests(
Expand All @@ -14619,14 +14631,8 @@ pub mod tests {
accounts_db.add_root(slot);
accounts_db.flush_accounts_cache(true, None);

let mut storage_maps: SnapshotStorage = accounts_db
.storage
.get_slot_storage_entries(slot)
.unwrap_or_default();

// Flushing cache should only create one storage entry
assert_eq!(storage_maps.len(), 1);
let storage0 = storage_maps.pop().unwrap();
let storage0 = accounts_db.get_and_assert_single_storage(slot);
let accounts = storage0.all_accounts();

for account in accounts {
Expand Down Expand Up @@ -15104,9 +15110,7 @@ pub mod tests {
db.clean_accounts(Some(1), false, None);

// Shrink Slot 0
let mut slot0_stores = db.storage.get_slot_storage_entries(0).unwrap();
assert_eq!(slot0_stores.len(), 1);
let slot0_store = slot0_stores.pop().unwrap();
let slot0_store = db.get_and_assert_single_storage(0);
{
let mut shrink_candidate_slots = db.shrink_candidate_slots.lock().unwrap();
shrink_candidate_slots
Expand All @@ -15124,7 +15128,7 @@ pub mod tests {
db.flush_accounts_cache(true, None);

// Should be one store before clean for slot 0
assert_eq!(db.storage.get_slot_storage_entries(0).unwrap().len(), 1);
db.get_and_assert_single_storage(0);
db.get_accounts_delta_hash(2);
db.clean_accounts(Some(2), false, None);

Expand Down Expand Up @@ -15442,9 +15446,7 @@ pub mod tests {
return;
}
// Simulate adding shrink candidates from clean_accounts()
let stores = db.storage.get_slot_storage_entries(slot).unwrap();
assert_eq!(stores.len(), 1);
let store = &stores[0];
let store = db.get_and_assert_single_storage(slot);
let store_id = store.append_vec_id();
db.shrink_candidate_slots
.lock()
Expand Down

0 comments on commit 337b4fe

Please sign in to comment.