Block queue mem limit test

This commit is contained in:
arkpar 2016-02-25 17:14:45 +01:00
parent bed89d0740
commit 0344f2b4c9
2 changed files with 39 additions and 2 deletions

View File

@ -30,6 +30,9 @@ use util::panics::*;
known_heap_size!(0, UnVerifiedBlock, VerifyingBlock, PreVerifiedBlock); known_heap_size!(0, UnVerifiedBlock, VerifyingBlock, PreVerifiedBlock);
const MIN_MEM_LIMIT: usize = 16384;
const MIN_QUEUE_LIMIT: usize = 512;
/// Block queue configuration /// Block queue configuration
#[derive(Debug)] #[derive(Debug)]
pub struct BlockQueueConfig { pub struct BlockQueueConfig {
@ -178,8 +181,8 @@ impl BlockQueue {
deleting: deleting.clone(), deleting: deleting.clone(),
processing: RwLock::new(HashSet::new()), processing: RwLock::new(HashSet::new()),
empty: empty.clone(), empty: empty.clone(),
max_queue_size: config.max_queue_size, max_queue_size: max(config.max_queue_size, MIN_QUEUE_LIMIT),
max_mem_use: config.max_mem_use, max_mem_use: max(config.max_mem_use, MIN_MEM_LIMIT),
} }
} }
@ -480,4 +483,19 @@ mod tests {
assert!(queue.queue_info().is_empty()); assert!(queue.queue_info().is_empty());
} }
#[test]
fn test_mem_limit() {
let spec = get_test_spec();
let engine = spec.to_engine().unwrap();
let mut config = BlockQueueConfig::default();
config.max_mem_use = super::MIN_MEM_LIMIT; // empty queue uses about 15000
let mut queue = BlockQueue::new(config, Arc::new(engine), IoChannel::disconnected());
assert!(!queue.queue_info().is_full());
let mut blocks = get_good_dummy_block_seq(50);
for b in blocks.drain(..) {
queue.import_block(b).unwrap();
}
assert!(queue.queue_info().is_full());
}
} }

View File

@ -253,6 +253,25 @@ pub fn get_temp_state_in(path: &Path) -> State {
State::new(journal_db, U256::from(0u8)) State::new(journal_db, U256::from(0u8))
} }
pub fn get_good_dummy_block_seq(count: usize) -> Vec<Bytes> {
let test_spec = get_test_spec();
let test_engine = test_spec.to_engine().unwrap();
let mut parent = test_engine.spec().genesis_header().hash();
let mut r = Vec::new();
for i in 1 .. count + 1 {
let mut block_header = Header::new();
block_header.gas_limit = decode(test_engine.spec().engine_params.get("minGasLimit").unwrap());
block_header.difficulty = decode(test_engine.spec().engine_params.get("minimumDifficulty").unwrap());
block_header.timestamp = i as u64;
block_header.number = i as u64;
block_header.parent_hash = parent;
block_header.state_root = test_engine.spec().genesis_header().state_root;
parent = block_header.hash();
r.push(create_test_block(&block_header));
}
r
}
pub fn get_good_dummy_block() -> Bytes { pub fn get_good_dummy_block() -> Bytes {
let mut block_header = Header::new(); let mut block_header = Header::new();
let test_spec = get_test_spec(); let test_spec = get_test_spec();