Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moves CacheHashData test-only methods into tests module #33170

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions accounts-db/src/cache_hash_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,23 +254,6 @@ impl CacheHashData {
}
}

#[cfg(test)]
/// load from 'file_name' into 'accumulator'
pub(crate) fn load(
&self,
file_name: impl AsRef<Path>,
accumulator: &mut SavedType,
start_bin_index: usize,
bin_calculator: &PubkeyBinCalculator24,
) -> Result<(), std::io::Error> {
let mut m = Measure::start("overall");
let cache_file = self.load_map(file_name)?;
cache_file.load_all(accumulator, start_bin_index, bin_calculator);
m.stop();
self.stats.load_us.fetch_add(m.as_us(), Ordering::Relaxed);
Ok(())
}

/// open a cache hash file, but don't map it.
/// This allows callers to know a file exists, but preserves the # mmapped files.
pub(crate) fn get_file_reference_to_map_later(
Expand Down Expand Up @@ -298,13 +281,6 @@ impl CacheHashData {
})
}

#[cfg(test)]
/// map 'file_name' into memory
fn load_map(&self, file_name: impl AsRef<Path>) -> Result<CacheHashDataFile, std::io::Error> {
let reference = self.get_file_reference_to_map_later(file_name)?;
reference.map()
}

pub(crate) fn pre_existing_cache_file_will_be_used(&self, file_name: impl AsRef<Path>) {
self.pre_existing_cache_files
.lock()
Expand Down Expand Up @@ -382,9 +358,36 @@ impl CacheHashData {
}

#[cfg(test)]
pub mod tests {
mod tests {
use {super::*, rand::Rng};

impl CacheHashData {
/// load from 'file_name' into 'accumulator'
fn load(
&self,
file_name: impl AsRef<Path>,
accumulator: &mut SavedType,
start_bin_index: usize,
bin_calculator: &PubkeyBinCalculator24,
) -> Result<(), std::io::Error> {
let mut m = Measure::start("overall");
let cache_file = self.load_map(file_name)?;
cache_file.load_all(accumulator, start_bin_index, bin_calculator);
m.stop();
self.stats.load_us.fetch_add(m.as_us(), Ordering::Relaxed);
Ok(())
}

/// map 'file_name' into memory
fn load_map(
&self,
file_name: impl AsRef<Path>,
) -> Result<CacheHashDataFile, std::io::Error> {
let reference = self.get_file_reference_to_map_later(file_name)?;
reference.map()
}
}

#[test]
fn test_read_write() {
// generate sample data
Expand Down