Update address manager test

The two tests have been combined into a single one. Added extra
log points for better debugging in CI if it gets stuck.
This commit is contained in:
codeShark149 2021-07-10 12:25:30 +05:30 committed by rajarshimaitra
parent 70d2a0ee6b
commit 377e5cdd49
No known key found for this signature in database
GPG Key ID: 558ACE7DBB4377C8

View File

@ -690,7 +690,7 @@ mod test {
use super::*; use super::*;
#[test] #[test]
fn test_crawl_times() { fn test_address_manager() {
// Initiate a manager with an non existent cache file name. // Initiate a manager with an non existent cache file name.
// It will create a new cache file // It will create a new cache file
let mut manager = AddressManager::new( let mut manager = AddressManager::new(
@ -704,9 +704,11 @@ mod test {
.unwrap(); .unwrap();
// start the crawlers and time them // start the crawlers and time them
println!("Starting manager and initial fetch");
let start = std::time::Instant::now(); let start = std::time::Instant::now();
manager.fetch().unwrap(); manager.fetch().unwrap();
let duration1 = start.elapsed(); let duration1 = start.elapsed();
println!("Completed Initial fetch");
// Create a new manager from existing cache and fetch again // Create a new manager from existing cache and fetch again
let mut manager = AddressManager::new( let mut manager = AddressManager::new(
@ -720,31 +722,18 @@ mod test {
.unwrap(); .unwrap();
// start the crawlers and time them // start the crawlers and time them
println!("Starting new fetch with previous cache");
let start = std::time::Instant::now(); let start = std::time::Instant::now();
manager.fetch().unwrap(); manager.fetch().unwrap();
let duration2 = start.elapsed(); let duration2 = start.elapsed();
println!("Completed new fetch()");
println!("Time taken for initial crawl: {:#?}", duration1); println!("Time taken for initial crawl: {:#?}", duration1);
println!("Time taken for next crawl {:#?}", duration2); println!("Time taken for next crawl {:#?}", duration2);
}
#[test] // Check Buffer Management
fn test_buffer_management() {
// Initiate a manager with an non existent cache file name.
// It will create a new cache file
let mut manager = AddressManager::new(
Network::Bitcoin,
"addr_cache".to_string(),
20,
None,
None,
LogDiscoveryProgress,
)
.unwrap();
// Start the first fetch()
manager.fetch().unwrap();
println!("Checking buffer management");
// Fetch few new address and ensure buffer goes to zero // Fetch few new address and ensure buffer goes to zero
let mut addrs_list = Vec::new(); let mut addrs_list = Vec::new();
for _ in 0..5 { for _ in 0..5 {
@ -763,9 +752,12 @@ mod test {
// Calling fetch again should start crawlers until buffer // Calling fetch again should start crawlers until buffer
// requirements are matched. // requirements are matched.
println!("Address buffer exhausted, starting new fetch");
manager.fetch().unwrap(); manager.fetch().unwrap();
println!("Fetch Complete");
// It should again have a cbf buffer of 5 // It should again have a cbf buffer of 5
assert_eq!(manager.directory.get_cbf_buffer(), 5); assert_eq!(manager.directory.get_cbf_buffer(), 5);
println!("Buffer management passed");
} }
} }