Skip to content

Commit

Permalink
simplify test_get_snapshot_accounts_hardlink_dir with fake paths
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangzhu70 committed Feb 15, 2023
1 parent 257a9e8 commit 38dda74
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
11 changes: 10 additions & 1 deletion runtime/src/accounts_background_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ impl AccountsBackgroundService {
last_snapshot_storages = Some(snapshot_storages);
debug!(
"Number of snapshot storages kept alive for fastboot: {}",
last_snapshot_storages
&last_snapshot_storages
.map(|storages| storages.len())
.unwrap_or(0)
);
Expand All @@ -655,8 +655,17 @@ impl AccountsBackgroundService {
stats.record_and_maybe_submit(start_time.elapsed());
sleep(Duration::from_millis(INTERVAL_MS));
}
/*
info!(
"ABS loop done. Number of snapshot storages kept alive for fastboot: {}",
last_snapshot_storages
.map(|storages| storages.len())
.unwrap_or(0)
);
*/
})
.unwrap();

Self { t_background }
}

Expand Down
29 changes: 10 additions & 19 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2643,7 +2643,6 @@ mod tests {
assert_matches::assert_matches,
bincode::{deserialize_from, serialize_into},
solana_sdk::{
account::AccountSharedData,
genesis_config::create_genesis_config,
native_token::sol_to_lamports,
signature::{Keypair, Signer},
Expand Down Expand Up @@ -4440,33 +4439,24 @@ mod tests {
#[test]
fn test_get_snapshot_accounts_hardlink_dir() {
solana_logger::setup();
let genesis_config = GenesisConfig::default();
let bank = Bank::new_for_tests(&genesis_config);
let db = &bank.accounts().accounts_db;
let slot = bank.slot();

let key = Pubkey::default();
let account = AccountSharedData::new(1, 0, &key);

db.store_for_tests(slot, &[(&key, &account)]);
db.add_root_and_flush_write_cache(slot);

let storages = bank.get_snapshot_storages(None);
let appendvec0 = storages.first().unwrap();

let appendvec_path = appendvec0.get_path();
let slot: Slot = 1;

let mut account_paths: HashSet<PathBuf> = HashSet::new();
let mut account_paths_set: HashSet<PathBuf> = HashSet::new();

let bank_snapshots_dir_tmp = tempfile::TempDir::new().unwrap();
let bank_snapshot_dir = bank_snapshots_dir_tmp.path().join(slot.to_string());
let accounts_hardlinks_dir = bank_snapshot_dir.join("accounts_hardlinks");
fs::create_dir_all(&accounts_hardlinks_dir).unwrap();

let (_tmp_dir, accounts_dir) = create_tmp_accounts_dir_for_tests();
let appendvec_filename = format!("{slot}.0");
let appendvec_path = accounts_dir.join(appendvec_filename);

let ret = get_snapshot_accounts_hardlink_dir(
&appendvec_path,
slot,
&mut account_paths,
&mut account_paths_set,
&accounts_hardlinks_dir,
);
assert!(ret.is_ok());
Expand All @@ -4480,9 +4470,10 @@ mod tests {
let ret = get_snapshot_accounts_hardlink_dir(
&wrong_appendvec_path,
slot,
&mut account_paths,
&mut account_paths_set,
accounts_hardlinks_dir,
);
assert!(ret.is_err());

assert!(matches!(ret, Err(SnapshotError::InvalidAppendVecPath(_))));
}
}

0 comments on commit 38dda74

Please sign in to comment.