add tests for handle_dropped_roots_for_ancient (#28703)

This commit is contained in:
Jeff Washington (jwash) 2022-11-01 09:03:54 -07:00 committed by GitHub
parent 0b51b15af2
commit daf71003d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 0 deletions

View File

@ -17567,6 +17567,55 @@ pub mod tests {
}
}
#[test]
fn test_handle_dropped_roots_for_ancient() {
solana_logger::setup();
let db = AccountsDb::new_single_for_tests();
db.handle_dropped_roots_for_ancient(Vec::default());
let slot0 = 0;
let dropped_roots = vec![slot0];
db.bank_hashes
.write()
.unwrap()
.insert(slot0, BankHashInfo::default());
db.storage.map.insert(slot0, Arc::default());
assert!(!db.bank_hashes.read().unwrap().is_empty());
db.accounts_index.add_root(slot0, false);
assert!(db.accounts_index.is_uncleaned_root(slot0));
assert!(db.accounts_index.is_alive_root(slot0));
db.handle_dropped_roots_for_ancient(dropped_roots);
assert!(db.bank_hashes.read().unwrap().is_empty());
assert!(!db.accounts_index.is_uncleaned_root(slot0));
assert!(!db.accounts_index.is_alive_root(slot0));
}
#[test]
#[should_panic(
expected = "assertion failed: self.storage.map.remove(slot).unwrap().1.read().unwrap().is_empty()"
)]
fn test_handle_dropped_roots_for_ancient_assert() {
solana_logger::setup();
let common_store_path = Path::new("");
let store_file_size = 2 * PAGE_SIZE;
let entry = Arc::new(AccountStorageEntry::new(
common_store_path,
0,
1,
store_file_size,
));
let db = AccountsDb::new_single_for_tests();
let slot0 = 0;
let dropped_roots = vec![slot0];
db.bank_hashes
.write()
.unwrap()
.insert(slot0, BankHashInfo::default());
let mut hm = HashMap::default();
hm.insert(0, entry);
db.storage.map.insert(slot0, Arc::new(RwLock::new(hm)));
db.handle_dropped_roots_for_ancient(dropped_roots);
}
#[test]
fn test_should_move_to_ancient_append_vec() {
solana_logger::setup();