refactor SnapshotStorage helpers to prepare for later changes (#17560)

This commit is contained in:
Jeff Washington (jwash) 2021-05-28 13:54:53 -05:00 committed by GitHub
parent 86c07bf785
commit 654918ab27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 16 deletions

View File

@ -5599,13 +5599,18 @@ pub mod tests {
ancestors
}
fn empty_storages<'a>() -> &'a [SnapshotStorage] {
&[]
}
#[test]
#[should_panic(expected = "assertion failed: bins <= max_plus_1 && bins > 0")]
fn test_accountsdb_scan_snapshot_stores_illegal_bins2() {
let mut stats = HashStats::default();
let bounds = Range { start: 0, end: 0 };
AccountsDb::scan_snapshot_stores(&[], &mut stats, 257, &bounds, false).unwrap();
AccountsDb::scan_snapshot_stores(&empty_storages(), &mut stats, 257, &bounds, false)
.unwrap();
}
#[test]
#[should_panic(expected = "assertion failed: bins <= max_plus_1 && bins > 0")]
@ -5613,7 +5618,7 @@ pub mod tests {
let mut stats = HashStats::default();
let bounds = Range { start: 0, end: 0 };
AccountsDb::scan_snapshot_stores(&[], &mut stats, 0, &bounds, false).unwrap();
AccountsDb::scan_snapshot_stores(&empty_storages(), &mut stats, 0, &bounds, false).unwrap();
}
#[test]
@ -5624,7 +5629,7 @@ pub mod tests {
let mut stats = HashStats::default();
let bounds = Range { start: 2, end: 2 };
AccountsDb::scan_snapshot_stores(&[], &mut stats, 2, &bounds, false).unwrap();
AccountsDb::scan_snapshot_stores(&empty_storages(), &mut stats, 2, &bounds, false).unwrap();
}
#[test]
#[should_panic(
@ -5634,7 +5639,7 @@ pub mod tests {
let mut stats = HashStats::default();
let bounds = Range { start: 1, end: 3 };
AccountsDb::scan_snapshot_stores(&[], &mut stats, 2, &bounds, false).unwrap();
AccountsDb::scan_snapshot_stores(&empty_storages(), &mut stats, 2, &bounds, false).unwrap();
}
#[test]
@ -5645,7 +5650,7 @@ pub mod tests {
let mut stats = HashStats::default();
let bounds = Range { start: 1, end: 0 };
AccountsDb::scan_snapshot_stores(&[], &mut stats, 2, &bounds, false).unwrap();
AccountsDb::scan_snapshot_stores(&empty_storages(), &mut stats, 2, &bounds, false).unwrap();
}
fn sample_storages_and_accounts() -> (SnapshotStorages, Vec<CalculateHashIntermediate>) {
@ -5726,6 +5731,11 @@ pub mod tests {
(storages, raw_expected)
}
fn get_storage_refs(input: &[SnapshotStorage]) -> &[SnapshotStorage] {
// these types will be refactored later and this will be a convenient helper function for tests
input
}
#[test]
fn test_accountsdb_scan_snapshot_stores() {
solana_logger::setup();
@ -5735,7 +5745,7 @@ pub mod tests {
let mut stats = HashStats::default();
let result = AccountsDb::scan_snapshot_stores(
&storages,
&get_storage_refs(&storages),
&mut stats,
bins,
&Range {
@ -5749,7 +5759,7 @@ pub mod tests {
let bins = 2;
let result = AccountsDb::scan_snapshot_stores(
&storages,
&get_storage_refs(&storages),
&mut stats,
bins,
&Range {
@ -5768,7 +5778,7 @@ pub mod tests {
let bins = 4;
let result = AccountsDb::scan_snapshot_stores(
&storages,
&get_storage_refs(&storages),
&mut stats,
bins,
&Range {
@ -5787,7 +5797,7 @@ pub mod tests {
let bins = 256;
let result = AccountsDb::scan_snapshot_stores(
&storages,
&get_storage_refs(&storages),
&mut stats,
bins,
&Range {
@ -5811,7 +5821,7 @@ pub mod tests {
let mut stats = HashStats::default();
let result = AccountsDb::scan_snapshot_stores(
&storages,
&get_storage_refs(&storages),
&mut stats,
bins,
&Range {
@ -5835,7 +5845,7 @@ pub mod tests {
// just the first bin of 2
let bins = 2;
let result = AccountsDb::scan_snapshot_stores(
&storages,
&get_storage_refs(&storages),
&mut stats,
bins,
&Range {
@ -5852,7 +5862,7 @@ pub mod tests {
// just the second bin of 2
let result = AccountsDb::scan_snapshot_stores(
&storages,
&get_storage_refs(&storages),
&mut stats,
bins,
&Range {
@ -5872,7 +5882,7 @@ pub mod tests {
let bins = 4;
for bin in 0..bins {
let result = AccountsDb::scan_snapshot_stores(
&storages,
&get_storage_refs(&storages),
&mut stats,
bins,
&Range {
@ -5891,7 +5901,7 @@ pub mod tests {
let bin_locations = vec![0, 127, 128, 255];
for bin in 0..bins {
let result = AccountsDb::scan_snapshot_stores(
&storages,
&get_storage_refs(&storages),
&mut stats,
bins,
&Range {
@ -5917,7 +5927,7 @@ pub mod tests {
let mut stats = HashStats::default();
let result = AccountsDb::scan_snapshot_stores(
&storages,
&get_storage_refs(&storages),
&mut stats,
bins,
&Range {
@ -6003,7 +6013,7 @@ pub mod tests {
let calls = AtomicU64::new(0);
let result = AccountsDb::scan_account_storage_no_bank(
&storages,
&get_storage_refs(&storages),
|loaded_account: LoadedAccount, accum: &mut Vec<u64>, slot: Slot| {
calls.fetch_add(1, Ordering::Relaxed);
assert_eq!(loaded_account.pubkey(), &pubkey);