From f4816dc0cf141ec73edc0810d9cceb104735ce74 Mon Sep 17 00:00:00 2001 From: Brooks Date: Wed, 6 Sep 2023 15:25:58 -0400 Subject: [PATCH] Moves CacheHashData test-only methods into tests module (#33170) --- accounts-db/src/cache_hash_data.rs | 53 ++++++++++++++++-------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/accounts-db/src/cache_hash_data.rs b/accounts-db/src/cache_hash_data.rs index a86822eb85..196474f49c 100644 --- a/accounts-db/src/cache_hash_data.rs +++ b/accounts-db/src/cache_hash_data.rs @@ -254,23 +254,6 @@ impl CacheHashData { } } - #[cfg(test)] - /// load from 'file_name' into 'accumulator' - pub(crate) fn load( - &self, - file_name: impl AsRef, - 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( @@ -298,13 +281,6 @@ impl CacheHashData { }) } - #[cfg(test)] - /// map 'file_name' into memory - fn load_map(&self, file_name: impl AsRef) -> Result { - 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) { self.pre_existing_cache_files .lock() @@ -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, + 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, + ) -> Result { + let reference = self.get_file_reference_to_map_later(file_name)?; + reference.map() + } + } + #[test] fn test_read_write() { // generate sample data