create test function test_process_blockstore (#19432)
This commit is contained in:
parent
af33012dc8
commit
f1d9c014f8
|
@ -83,8 +83,10 @@ impl BlockCostCapacityMeter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type BlockstoreProcessorInner = (BankForks, LeaderScheduleCache);
|
||||||
|
|
||||||
pub type BlockstoreProcessorResult =
|
pub type BlockstoreProcessorResult =
|
||||||
result::Result<(BankForks, LeaderScheduleCache), BlockstoreProcessorError>;
|
result::Result<BlockstoreProcessorInner, BlockstoreProcessorError>;
|
||||||
|
|
||||||
thread_local!(static PAR_THREAD_POOL: RefCell<ThreadPool> = RefCell::new(rayon::ThreadPoolBuilder::new()
|
thread_local!(static PAR_THREAD_POOL: RefCell<ThreadPool> = RefCell::new(rayon::ThreadPoolBuilder::new()
|
||||||
.num_threads(get_thread_count())
|
.num_threads(get_thread_count())
|
||||||
|
@ -1436,6 +1438,14 @@ pub mod tests {
|
||||||
use std::{collections::BTreeSet, sync::RwLock};
|
use std::{collections::BTreeSet, sync::RwLock};
|
||||||
use trees::tr;
|
use trees::tr;
|
||||||
|
|
||||||
|
fn test_process_blockstore(
|
||||||
|
genesis_config: &GenesisConfig,
|
||||||
|
blockstore: &Blockstore,
|
||||||
|
opts: ProcessOptions,
|
||||||
|
) -> BlockstoreProcessorInner {
|
||||||
|
process_blockstore(genesis_config, blockstore, Vec::new(), opts, None).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_process_blockstore_with_missing_hashes() {
|
fn test_process_blockstore_with_missing_hashes() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
|
@ -1596,7 +1606,7 @@ pub mod tests {
|
||||||
..ProcessOptions::default()
|
..ProcessOptions::default()
|
||||||
};
|
};
|
||||||
let (bank_forks, _leader_schedule) =
|
let (bank_forks, _leader_schedule) =
|
||||||
process_blockstore(&genesis_config, &blockstore, Vec::new(), opts, None).unwrap();
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
assert_eq!(frozen_bank_slots(&bank_forks), vec![0]);
|
assert_eq!(frozen_bank_slots(&bank_forks), vec![0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1662,7 +1672,7 @@ pub mod tests {
|
||||||
..ProcessOptions::default()
|
..ProcessOptions::default()
|
||||||
};
|
};
|
||||||
let (bank_forks, _leader_schedule) =
|
let (bank_forks, _leader_schedule) =
|
||||||
process_blockstore(&genesis_config, &blockstore, Vec::new(), opts, None).unwrap();
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
|
|
||||||
assert_eq!(frozen_bank_slots(&bank_forks), vec![0]); // slot 1 isn't "full", we stop at slot zero
|
assert_eq!(frozen_bank_slots(&bank_forks), vec![0]); // slot 1 isn't "full", we stop at slot zero
|
||||||
|
|
||||||
|
@ -1682,7 +1692,7 @@ pub mod tests {
|
||||||
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 3, 0, blockhash);
|
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 3, 0, blockhash);
|
||||||
// Slot 0 should not show up in the ending bank_forks_info
|
// Slot 0 should not show up in the ending bank_forks_info
|
||||||
let (bank_forks, _leader_schedule) =
|
let (bank_forks, _leader_schedule) =
|
||||||
process_blockstore(&genesis_config, &blockstore, Vec::new(), opts, None).unwrap();
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
|
|
||||||
// slot 1 isn't "full", we stop at slot zero
|
// slot 1 isn't "full", we stop at slot zero
|
||||||
assert_eq!(frozen_bank_slots(&bank_forks), vec![0, 3]);
|
assert_eq!(frozen_bank_slots(&bank_forks), vec![0, 3]);
|
||||||
|
@ -1750,7 +1760,7 @@ pub mod tests {
|
||||||
..ProcessOptions::default()
|
..ProcessOptions::default()
|
||||||
};
|
};
|
||||||
let (bank_forks, _leader_schedule) =
|
let (bank_forks, _leader_schedule) =
|
||||||
process_blockstore(&genesis_config, &blockstore, Vec::new(), opts, None).unwrap();
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
|
|
||||||
// One fork, other one is ignored b/c not a descendant of the root
|
// One fork, other one is ignored b/c not a descendant of the root
|
||||||
assert_eq!(frozen_bank_slots(&bank_forks), vec![4]);
|
assert_eq!(frozen_bank_slots(&bank_forks), vec![4]);
|
||||||
|
@ -1830,7 +1840,7 @@ pub mod tests {
|
||||||
..ProcessOptions::default()
|
..ProcessOptions::default()
|
||||||
};
|
};
|
||||||
let (bank_forks, _leader_schedule) =
|
let (bank_forks, _leader_schedule) =
|
||||||
process_blockstore(&genesis_config, &blockstore, Vec::new(), opts, None).unwrap();
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
|
|
||||||
assert_eq!(frozen_bank_slots(&bank_forks), vec![1, 2, 3, 4]);
|
assert_eq!(frozen_bank_slots(&bank_forks), vec![1, 2, 3, 4]);
|
||||||
assert_eq!(bank_forks.working_bank().slot(), 4);
|
assert_eq!(bank_forks.working_bank().slot(), 4);
|
||||||
|
@ -2047,7 +2057,7 @@ pub mod tests {
|
||||||
..ProcessOptions::default()
|
..ProcessOptions::default()
|
||||||
};
|
};
|
||||||
let (bank_forks, _leader_schedule) =
|
let (bank_forks, _leader_schedule) =
|
||||||
process_blockstore(&genesis_config, &blockstore, Vec::new(), opts, None).unwrap();
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
|
|
||||||
// There is one fork, head is last_slot + 1
|
// There is one fork, head is last_slot + 1
|
||||||
assert_eq!(frozen_bank_slots(&bank_forks), vec![last_slot + 1]);
|
assert_eq!(frozen_bank_slots(&bank_forks), vec![last_slot + 1]);
|
||||||
|
@ -2191,7 +2201,7 @@ pub mod tests {
|
||||||
..ProcessOptions::default()
|
..ProcessOptions::default()
|
||||||
};
|
};
|
||||||
let (bank_forks, _leader_schedule) =
|
let (bank_forks, _leader_schedule) =
|
||||||
process_blockstore(&genesis_config, &blockstore, Vec::new(), opts, None).unwrap();
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
|
|
||||||
assert_eq!(frozen_bank_slots(&bank_forks), vec![0, 1]);
|
assert_eq!(frozen_bank_slots(&bank_forks), vec![0, 1]);
|
||||||
assert_eq!(bank_forks.root(), 0);
|
assert_eq!(bank_forks.root(), 0);
|
||||||
|
@ -2221,7 +2231,7 @@ pub mod tests {
|
||||||
..ProcessOptions::default()
|
..ProcessOptions::default()
|
||||||
};
|
};
|
||||||
let (bank_forks, _leader_schedule) =
|
let (bank_forks, _leader_schedule) =
|
||||||
process_blockstore(&genesis_config, &blockstore, Vec::new(), opts, None).unwrap();
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
|
|
||||||
assert_eq!(frozen_bank_slots(&bank_forks), vec![0]);
|
assert_eq!(frozen_bank_slots(&bank_forks), vec![0]);
|
||||||
let bank = bank_forks[0].clone();
|
let bank = bank_forks[0].clone();
|
||||||
|
@ -2239,7 +2249,7 @@ pub mod tests {
|
||||||
accounts_db_test_hash_calculation: true,
|
accounts_db_test_hash_calculation: true,
|
||||||
..ProcessOptions::default()
|
..ProcessOptions::default()
|
||||||
};
|
};
|
||||||
process_blockstore(&genesis_config, &blockstore, Vec::new(), opts, None).unwrap();
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
PAR_THREAD_POOL.with(|pool| {
|
PAR_THREAD_POOL.with(|pool| {
|
||||||
assert_eq!(pool.borrow().current_num_threads(), 1);
|
assert_eq!(pool.borrow().current_num_threads(), 1);
|
||||||
});
|
});
|
||||||
|
@ -2257,7 +2267,7 @@ pub mod tests {
|
||||||
..ProcessOptions::default()
|
..ProcessOptions::default()
|
||||||
};
|
};
|
||||||
let (_bank_forks, leader_schedule) =
|
let (_bank_forks, leader_schedule) =
|
||||||
process_blockstore(&genesis_config, &blockstore, Vec::new(), opts, None).unwrap();
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
assert_eq!(leader_schedule.max_schedules(), std::usize::MAX);
|
assert_eq!(leader_schedule.max_schedules(), std::usize::MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2318,7 +2328,7 @@ pub mod tests {
|
||||||
accounts_db_test_hash_calculation: true,
|
accounts_db_test_hash_calculation: true,
|
||||||
..ProcessOptions::default()
|
..ProcessOptions::default()
|
||||||
};
|
};
|
||||||
process_blockstore(&genesis_config, &blockstore, Vec::new(), opts, None).unwrap();
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
assert_eq!(*callback_counter.write().unwrap(), 2);
|
assert_eq!(*callback_counter.write().unwrap(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2967,7 +2977,7 @@ pub mod tests {
|
||||||
..ProcessOptions::default()
|
..ProcessOptions::default()
|
||||||
};
|
};
|
||||||
let (bank_forks, _leader_schedule) =
|
let (bank_forks, _leader_schedule) =
|
||||||
process_blockstore(&genesis_config, &blockstore, Vec::new(), opts, None).unwrap();
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
|
|
||||||
// Should be able to fetch slot 0 because we specified halting at slot 0, even
|
// Should be able to fetch slot 0 because we specified halting at slot 0, even
|
||||||
// if there is a greater root at slot 1.
|
// if there is a greater root at slot 1.
|
||||||
|
@ -3562,7 +3572,7 @@ pub mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let (bank_forks, _leader_schedule) =
|
let (bank_forks, _leader_schedule) =
|
||||||
process_blockstore(&genesis_config, &blockstore, Vec::new(), opts, None).unwrap();
|
test_process_blockstore(&genesis_config, &blockstore, opts);
|
||||||
|
|
||||||
assert_eq!(bank_forks.root(), really_expected_root_slot);
|
assert_eq!(bank_forks.root(), really_expected_root_slot);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue