Cleanup snapshot integration tests (#26390)

This commit is contained in:
Brooks Prumo 2022-07-05 09:23:23 -05:00 committed by GitHub
parent 95ae82e074
commit 9ec38a3191
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 987 additions and 993 deletions

23
Cargo.lock generated
View File

@ -4981,6 +4981,7 @@ dependencies = [
"sysctl",
"systemstat",
"tempfile",
"test-case",
"thiserror",
"tokio",
"trees",
@ -6810,6 +6811,28 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13a4ec180a2de59b57434704ccfad967f789b12737738798fa08798cd5824c16"
[[package]]
name = "test-case"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "196e8a70562e252cc51eaaaee3ecddc39803d9b7fd4a772b7c7dae7cdf42a859"
dependencies = [
"test-case-macros",
]
[[package]]
name = "test-case-macros"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dd461f47ade621665c9f4e44b20449341769911c253275dc5cb03726cbb852c"
dependencies = [
"cfg-if 1.0.0",
"proc-macro-error",
"proc-macro2 1.0.38",
"quote 1.0.18",
"syn 1.0.93",
]
[[package]]
name = "textwrap"
version = "0.11.0"

View File

@ -74,6 +74,7 @@ solana-program-runtime = { path = "../program-runtime", version = "=1.11.2" }
solana-stake-program = { path = "../programs/stake", version = "=1.11.2" }
static_assertions = "1.1.0"
systemstat = "0.1.11"
test-case = "2.1.0"
[target."cfg(unix)".dependencies]
sysctl = "0.4.4"

View File

@ -1,51 +1,6 @@
// Long-running bank_forks tests
#![allow(clippy::integer_arithmetic)]
macro_rules! DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS {
($x:ident, $y:ident, $z:ident) => {
#[allow(non_snake_case)]
mod $z {
use super::*;
const SNAPSHOT_VERSION: SnapshotVersion = SnapshotVersion::$x;
const CLUSTER_TYPE: ClusterType = ClusterType::$y;
#[test]
fn test_bank_forks_status_cache_snapshot_n() {
run_test_bank_forks_status_cache_snapshot_n(SNAPSHOT_VERSION, CLUSTER_TYPE)
}
#[test]
fn test_bank_forks_snapshot_n() {
run_test_bank_forks_snapshot_n(SNAPSHOT_VERSION, CLUSTER_TYPE)
}
#[test]
fn test_concurrent_snapshot_packaging() {
run_test_concurrent_snapshot_packaging(SNAPSHOT_VERSION, CLUSTER_TYPE)
}
#[test]
fn test_slots_to_snapshot() {
run_test_slots_to_snapshot(SNAPSHOT_VERSION, CLUSTER_TYPE)
}
#[test]
fn test_bank_forks_incremental_snapshot_n() {
run_test_bank_forks_incremental_snapshot_n(SNAPSHOT_VERSION, CLUSTER_TYPE)
}
#[test]
fn test_snapshots_with_background_services() {
run_test_snapshots_with_background_services(SNAPSHOT_VERSION, CLUSTER_TYPE)
}
}
};
}
#[cfg(test)]
mod tests {
use {
use {
bincode::serialize_into,
crossbeam_channel::unbounded,
fs_extra::dir::CopyOptions,
@ -58,8 +13,7 @@ mod tests {
solana_gossip::{cluster_info::ClusterInfo, contact_info::ContactInfo},
solana_runtime::{
accounts_background_service::{
AbsRequestHandler, AbsRequestSender, AccountsBackgroundService,
SnapshotRequestHandler,
AbsRequestHandler, AbsRequestSender, AccountsBackgroundService, SnapshotRequestHandler,
},
accounts_db::{self, ACCOUNTS_DB_CONFIG_FOR_TESTING},
accounts_index::AccountSecondaryIndexes,
@ -72,12 +26,18 @@ mod tests {
AccountsPackage, PendingAccountsPackage, PendingSnapshotPackage, SnapshotPackage,
SnapshotType,
},
snapshot_utils::{self, ArchiveFormat, SnapshotVersion},
snapshot_utils::{
self, ArchiveFormat,
SnapshotVersion::{self, V1_2_0},
},
status_cache::MAX_CACHE_ENTRIES,
},
solana_sdk::{
clock::Slot,
genesis_config::{ClusterType, GenesisConfig},
genesis_config::{
ClusterType::{self, Development, Devnet, MainnetBeta, Testnet},
GenesisConfig,
},
hash::{hashv, Hash},
pubkey::Pubkey,
signature::{Keypair, Signer},
@ -97,14 +57,10 @@ mod tests {
time::Duration,
},
tempfile::TempDir,
};
test_case::test_case,
};
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, Development, V1_2_0_Development);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, Devnet, V1_2_0_Devnet);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, Testnet, V1_2_0_Testnet);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, MainnetBeta, V1_2_0_MainnetBeta);
struct SnapshotTestConfig {
struct SnapshotTestConfig {
accounts_dir: TempDir,
bank_snapshots_dir: TempDir,
full_snapshot_archives_dir: TempDir,
@ -112,9 +68,9 @@ mod tests {
snapshot_config: SnapshotConfig,
bank_forks: BankForks,
genesis_config_info: GenesisConfigInfo,
}
}
impl SnapshotTestConfig {
impl SnapshotTestConfig {
fn new(
snapshot_version: SnapshotVersion,
cluster_type: ClusterType,
@ -172,14 +128,14 @@ mod tests {
genesis_config_info,
}
}
}
}
fn restore_from_snapshot(
fn restore_from_snapshot(
old_bank_forks: &BankForks,
old_last_slot: Slot,
old_genesis_config: &GenesisConfig,
account_paths: &[PathBuf],
) {
) {
let full_snapshot_archives_dir = old_bank_forks
.snapshot_config
.as_ref()
@ -224,21 +180,21 @@ mod tests {
let bank = old_bank_forks.get(deserialized_bank.slot()).unwrap();
assert_eq!(bank.as_ref(), &deserialized_bank);
}
}
// creates banks up to "last_slot" and runs the input function `f` on each bank created
// also marks each bank as root and generates snapshots
// finally tries to restore from the last bank's snapshot and compares the restored bank to the
// `last_slot` bank
fn run_bank_forks_snapshot_n<F>(
// creates banks up to "last_slot" and runs the input function `f` on each bank created
// also marks each bank as root and generates snapshots
// finally tries to restore from the last bank's snapshot and compares the restored bank to the
// `last_slot` bank
fn run_bank_forks_snapshot_n<F>(
snapshot_version: SnapshotVersion,
cluster_type: ClusterType,
last_slot: Slot,
f: F,
set_root_interval: u64,
) where
) where
F: Fn(&mut Bank, &Keypair),
{
{
solana_logger::setup();
// Set up snapshotting config
let mut snapshot_test_config = SnapshotTestConfig::new(
@ -278,8 +234,7 @@ mod tests {
let last_bank = bank_forks.get(last_slot).unwrap();
let snapshot_config = &snapshot_test_config.snapshot_config;
let bank_snapshots_dir = &snapshot_config.bank_snapshots_dir;
let last_bank_snapshot_info =
snapshot_utils::get_highest_bank_snapshot_pre(bank_snapshots_dir)
let last_bank_snapshot_info = snapshot_utils::get_highest_bank_snapshot_pre(bank_snapshots_dir)
.expect("no bank snapshots found in path");
let slot_deltas = last_bank.status_cache.read().unwrap().root_slot_deltas();
let accounts_package = AccountsPackage::new(
@ -301,8 +256,7 @@ mod tests {
accounts_package.slot,
&last_bank.get_accounts_hash(),
);
let snapshot_package =
SnapshotPackage::new(accounts_package, last_bank.get_accounts_hash());
let snapshot_package = SnapshotPackage::new(accounts_package, last_bank.get_accounts_hash());
snapshot_utils::archive_snapshot_package(
&snapshot_package,
&snapshot_config.full_snapshot_archives_dir,
@ -316,12 +270,13 @@ mod tests {
let account_paths = &[snapshot_test_config.accounts_dir.path().to_path_buf()];
let genesis_config = &snapshot_test_config.genesis_config_info.genesis_config;
restore_from_snapshot(bank_forks, last_slot, genesis_config, account_paths);
}
}
fn run_test_bank_forks_snapshot_n(
snapshot_version: SnapshotVersion,
cluster_type: ClusterType,
) {
#[test_case(V1_2_0, Development)]
#[test_case(V1_2_0, Devnet)]
#[test_case(V1_2_0, Testnet)]
#[test_case(V1_2_0, MainnetBeta)]
fn test_bank_forks_snapshot(snapshot_version: SnapshotVersion, cluster_type: ClusterType) {
// create banks up to slot 4 and create 1 new account in each bank. test that bank 4 snapshots
// and restores correctly
run_bank_forks_snapshot_n(
@ -330,22 +285,20 @@ mod tests {
4,
|bank, mint_keypair| {
let key1 = Keypair::new().pubkey();
let tx =
system_transaction::transfer(mint_keypair, &key1, 1, bank.last_blockhash());
let tx = system_transaction::transfer(mint_keypair, &key1, 1, bank.last_blockhash());
assert_eq!(bank.process_transaction(&tx), Ok(()));
let key2 = Keypair::new().pubkey();
let tx =
system_transaction::transfer(mint_keypair, &key2, 0, bank.last_blockhash());
let tx = system_transaction::transfer(mint_keypair, &key2, 0, bank.last_blockhash());
assert_eq!(bank.process_transaction(&tx), Ok(()));
bank.freeze();
},
1,
);
}
}
fn goto_end_of_slot(bank: &mut Bank) {
fn goto_end_of_slot(bank: &mut Bank) {
let mut tick_hash = bank.last_blockhash();
loop {
tick_hash = hashv(&[tick_hash.as_ref(), &[42]]);
@ -355,12 +308,16 @@ mod tests {
return;
}
}
}
}
fn run_test_concurrent_snapshot_packaging(
#[test_case(V1_2_0, Development)]
#[test_case(V1_2_0, Devnet)]
#[test_case(V1_2_0, Testnet)]
#[test_case(V1_2_0, MainnetBeta)]
fn test_concurrent_snapshot_packaging(
snapshot_version: SnapshotVersion,
cluster_type: ClusterType,
) {
) {
solana_logger::setup();
// Set up snapshotting config
@ -585,9 +542,13 @@ mod tests {
ArchiveFormat::TarBzip2,
snapshot_utils::VerifyBank::NonDeterministic(saved_slot),
);
}
}
fn run_test_slots_to_snapshot(snapshot_version: SnapshotVersion, cluster_type: ClusterType) {
#[test_case(V1_2_0, Development)]
#[test_case(V1_2_0, Devnet)]
#[test_case(V1_2_0, Testnet)]
#[test_case(V1_2_0, MainnetBeta)]
fn test_slots_to_snapshot(snapshot_version: SnapshotVersion, cluster_type: ClusterType) {
solana_logger::setup();
let num_set_roots = MAX_CACHE_ENTRIES * 2;
@ -606,16 +567,13 @@ mod tests {
for _ in 0..num_set_roots {
for _ in 0..*add_root_interval {
let new_slot = current_bank.slot() + 1;
let new_bank =
Bank::new_from_parent(&current_bank, &Pubkey::default(), new_slot);
let new_bank = Bank::new_from_parent(&current_bank, &Pubkey::default(), new_slot);
snapshot_test_config.bank_forks.insert(new_bank);
current_bank = snapshot_test_config.bank_forks[new_slot].clone();
}
snapshot_test_config.bank_forks.set_root(
current_bank.slot(),
&request_sender,
None,
);
snapshot_test_config
.bank_forks
.set_root(current_bank.slot(), &request_sender, None);
}
let num_old_slots = num_set_roots * *add_root_interval - MAX_CACHE_ENTRIES + 1;
@ -635,12 +593,16 @@ mod tests {
.sorted();
assert!(slots_to_snapshot.into_iter().eq(expected_slots_to_snapshot));
}
}
}
fn run_test_bank_forks_status_cache_snapshot_n(
#[test_case(V1_2_0, Development)]
#[test_case(V1_2_0, Devnet)]
#[test_case(V1_2_0, Testnet)]
#[test_case(V1_2_0, MainnetBeta)]
fn test_bank_forks_status_cache_snapshot(
snapshot_version: SnapshotVersion,
cluster_type: ClusterType,
) {
) {
// create banks up to slot (MAX_CACHE_ENTRIES * 2) + 1 while transferring 1 lamport into 2 different accounts each time
// this is done to ensure the AccountStorageEntries keep getting cleaned up as the root moves
// ahead. Also tests the status_cache purge and status cache snapshotting.
@ -672,12 +634,16 @@ mod tests {
*set_root_interval,
);
}
}
}
fn run_test_bank_forks_incremental_snapshot_n(
#[test_case(V1_2_0, Development)]
#[test_case(V1_2_0, Devnet)]
#[test_case(V1_2_0, Testnet)]
#[test_case(V1_2_0, MainnetBeta)]
fn test_bank_forks_incremental_snapshot(
snapshot_version: SnapshotVersion,
cluster_type: ClusterType,
) {
) {
solana_logger::setup();
const SET_ROOT_INTERVAL: Slot = 2;
@ -748,8 +714,7 @@ mod tests {
// Since AccountsBackgroundService isn't running, manually make a full snapshot archive
// at the right interval
if snapshot_utils::should_take_full_snapshot(slot, FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS)
{
if snapshot_utils::should_take_full_snapshot(slot, FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS) {
make_full_snapshot_archive(&bank, &snapshot_test_config.snapshot_config).unwrap();
}
// Similarly, make an incremental snapshot archive at the right interval, but only if
@ -779,12 +744,12 @@ mod tests {
.unwrap();
}
}
}
}
fn make_full_snapshot_archive(
fn make_full_snapshot_archive(
bank: &Bank,
snapshot_config: &SnapshotConfig,
) -> snapshot_utils::Result<()> {
) -> snapshot_utils::Result<()> {
let slot = bank.slot();
info!("Making full snapshot archive from bank at slot: {}", slot);
let bank_snapshot_info =
@ -811,13 +776,13 @@ mod tests {
)?;
Ok(())
}
}
fn make_incremental_snapshot_archive(
fn make_incremental_snapshot_archive(
bank: &Bank,
incremental_snapshot_base_slot: Slot,
snapshot_config: &SnapshotConfig,
) -> snapshot_utils::Result<()> {
) -> snapshot_utils::Result<()> {
let slot = bank.slot();
info!(
"Making incremental snapshot archive from bank at slot: {}, and base slot: {}",
@ -849,14 +814,14 @@ mod tests {
)?;
Ok(())
}
}
fn restore_from_snapshots_and_check_banks_are_equal(
fn restore_from_snapshots_and_check_banks_are_equal(
bank: &Bank,
snapshot_config: &SnapshotConfig,
accounts_dir: PathBuf,
genesis_config: &GenesisConfig,
) -> snapshot_utils::Result<()> {
) -> snapshot_utils::Result<()> {
let (deserialized_bank, ..) = snapshot_utils::bank_from_latest_snapshot_archives(
&snapshot_config.bank_snapshots_dir,
&snapshot_config.full_snapshot_archives_dir,
@ -879,13 +844,17 @@ mod tests {
assert_eq!(bank, &deserialized_bank);
Ok(())
}
}
/// Spin up the background services fully and test taking snapshots
fn run_test_snapshots_with_background_services(
/// Spin up the background services fully and test taking snapshots
#[test_case(V1_2_0, Development)]
#[test_case(V1_2_0, Devnet)]
#[test_case(V1_2_0, Testnet)]
#[test_case(V1_2_0, MainnetBeta)]
fn test_snapshots_with_background_services(
snapshot_version: SnapshotVersion,
cluster_type: ClusterType,
) {
) {
solana_logger::setup();
const SET_ROOT_INTERVAL_SLOTS: Slot = 2;
@ -893,8 +862,8 @@ mod tests {
const INCREMENTAL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS: Slot = BANK_SNAPSHOT_INTERVAL_SLOTS * 3;
const FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS: Slot =
INCREMENTAL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS * 5;
const LAST_SLOT: Slot = FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS * 3
+ INCREMENTAL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS * 2;
const LAST_SLOT: Slot =
FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS * 3 + INCREMENTAL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS * 2;
info!("Running snapshots with background services test...");
trace!(
@ -1030,7 +999,9 @@ mod tests {
// NOTE: The 5 seconds of sleeping is arbitrary. This should be plenty of time since the
// snapshots should be quite small. If this test fails at `unwrap()` or because the bank
// slots do not match, increase this sleep duration.
info!("Sleeping for 5 seconds to give background services time to process snapshot archives...");
info!(
"Sleeping for 5 seconds to give background services time to process snapshot archives..."
);
std::thread::sleep(Duration::from_secs(5));
info!("Awake! Rebuilding bank from latest snapshot archives...");
@ -1075,5 +1046,4 @@ mod tests {
accounts_background_service.join().unwrap();
accounts_hash_verifier.join().unwrap();
snapshot_packager_service.join().unwrap();
}
}