Skip to content

Commit

Permalink
Removes unnecessary tests in snapshot_packager_service.rs (anza-xyz#1371
Browse files Browse the repository at this point in the history
)
  • Loading branch information
brooksprumo authored May 16, 2024
1 parent 4d5ad77 commit e01278e
Showing 1 changed file with 3 additions and 80 deletions.
83 changes: 3 additions & 80 deletions core/src/snapshot_packager_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,91 +196,14 @@ mod tests {
rand::seq::SliceRandom,
solana_runtime::{
snapshot_archive_info::SnapshotArchiveInfo,
snapshot_bank_utils,
snapshot_hash::SnapshotHash,
snapshot_package::{SnapshotKind, SnapshotPackage},
snapshot_utils::{self, ArchiveFormat, SnapshotVersion},
snapshot_utils::{ArchiveFormat, SnapshotVersion},
},
solana_sdk::{clock::Slot, genesis_config::GenesisConfig, hash::Hash},
std::{
fs::{self, remove_dir_all},
path::{Path, PathBuf},
time::Instant,
},
tempfile::TempDir,
solana_sdk::{clock::Slot, hash::Hash},
std::{path::PathBuf, time::Instant},
};

// Create temporary placeholder directory for all test files
fn make_tmp_dir_path() -> PathBuf {
let out_dir = std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string());
let path = PathBuf::from(format!("{out_dir}/tmp/test_package_snapshots"));

// whack any possible collision
let _ignored = std::fs::remove_dir_all(&path);
// whack any possible collision
let _ignored = std::fs::remove_file(&path);

path
}

#[test]
fn test_package_snapshots_relative_ledger_path() {
let temp_dir = make_tmp_dir_path();
create_and_verify_snapshot(&temp_dir);
remove_dir_all(temp_dir).expect("should remove tmp dir");
}

#[test]
fn test_package_snapshots() {
create_and_verify_snapshot(TempDir::new().unwrap().path())
}

fn create_and_verify_snapshot(temp_dir: &Path) {
let bank_snapshots_dir = temp_dir.join("snapshots");
fs::create_dir_all(&bank_snapshots_dir).unwrap();
let full_snapshot_archives_dir = temp_dir.join("full_snapshot_archives");
let incremental_snapshot_archives_dir = temp_dir.join("incremental_snapshot_archives");
fs::create_dir_all(&full_snapshot_archives_dir).unwrap();
fs::create_dir_all(&incremental_snapshot_archives_dir).unwrap();

let num_snapshots = 1;

let genesis_config = GenesisConfig::default();
let bank = snapshot_bank_utils::create_snapshot_dirs_for_tests(
&genesis_config,
&bank_snapshots_dir,
num_snapshots,
num_snapshots,
);

let bank_snapshot_info =
snapshot_utils::get_highest_bank_snapshot(&bank_snapshots_dir).unwrap();
let snapshot_storages = bank.get_snapshot_storages(None);
let archive_format = ArchiveFormat::Tar;

let full_archive = snapshot_bank_utils::package_and_archive_full_snapshot(
&bank,
&bank_snapshot_info,
full_snapshot_archives_dir,
incremental_snapshot_archives_dir,
snapshot_storages,
archive_format,
SnapshotVersion::default(),
snapshot_utils::DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
snapshot_utils::DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
)
.unwrap();

// Check archive is correct
snapshot_utils::verify_snapshot_archive(
full_archive.path(),
bank_snapshots_dir,
archive_format,
snapshot_utils::VerifyBank::Deterministic,
bank_snapshot_info.slot,
);
}

/// Ensure that unhandled snapshot packages are properly re-enqueued or dropped
///
/// The snapshot package handler should re-enqueue unhandled snapshot packages, if those
Expand Down

0 comments on commit e01278e

Please sign in to comment.