Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test method get_and_assert_single_storage #29481

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
storage_maps.pop().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