tests
This commit is contained in:
parent
67c5e376b8
commit
0e0f1fea69
@ -38,6 +38,8 @@ pub struct BlockQueueInfo {
|
|||||||
pub verified_queue_size: usize,
|
pub verified_queue_size: usize,
|
||||||
/// Number of blocks being verified
|
/// Number of blocks being verified
|
||||||
pub verifying_queue_size: usize,
|
pub verifying_queue_size: usize,
|
||||||
|
/// Indicates queue is empty
|
||||||
|
pub empty: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BlockQueueInfo {
|
impl BlockQueueInfo {
|
||||||
@ -285,7 +287,6 @@ impl BlockQueue {
|
|||||||
for h in hashes {
|
for h in hashes {
|
||||||
processing.remove(&h);
|
processing.remove(&h);
|
||||||
}
|
}
|
||||||
//TODO: reward peers
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes up to `max` verified blocks from the queue
|
/// Removes up to `max` verified blocks from the queue
|
||||||
@ -312,6 +313,7 @@ impl BlockQueue {
|
|||||||
verified_queue_size: verification.verified.len(),
|
verified_queue_size: verification.verified.len(),
|
||||||
unverified_queue_size: verification.unverified.len(),
|
unverified_queue_size: verification.unverified.len(),
|
||||||
verifying_queue_size: verification.verifying.len(),
|
verifying_queue_size: verification.verifying.len(),
|
||||||
|
empty: verification.verified.is_empty() && verification.unverified.is_empty() && verification.verifying.is_empty(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -393,4 +395,14 @@ mod tests {
|
|||||||
panic!("error importing block that has already been drained ({:?})", e);
|
panic!("error importing block that has already been drained ({:?})", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn returns_empty_once_finished() {
|
||||||
|
let mut queue = get_test_queue();
|
||||||
|
queue.import_block(get_good_dummy_block()).expect("error importing block that is valid by definition");
|
||||||
|
queue.flush();
|
||||||
|
queue.drain(1);
|
||||||
|
|
||||||
|
assert!(queue.queue_info().empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ use spec::Spec;
|
|||||||
use engine::Engine;
|
use engine::Engine;
|
||||||
use views::HeaderView;
|
use views::HeaderView;
|
||||||
use block_queue::{BlockQueue, BlockQueueInfo};
|
use block_queue::{BlockQueue, BlockQueueInfo};
|
||||||
use service::NetSyncMessage;
|
use service::{NetSyncMessage, SyncMessage};
|
||||||
use env_info::LastHashes;
|
use env_info::LastHashes;
|
||||||
use verification::*;
|
use verification::*;
|
||||||
use block::*;
|
use block::*;
|
||||||
@ -223,7 +223,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This is triggered by a message coming from a block queue when the block is ready for insertion
|
/// This is triggered by a message coming from a block queue when the block is ready for insertion
|
||||||
pub fn import_verified_blocks(&self, _io: &IoChannel<NetSyncMessage>) -> usize {
|
pub fn import_verified_blocks(&self, io: &IoChannel<NetSyncMessage>) -> usize {
|
||||||
let mut ret = 0;
|
let mut ret = 0;
|
||||||
let mut bad = HashSet::new();
|
let mut bad = HashSet::new();
|
||||||
let _import_lock = self.import_lock.lock();
|
let _import_lock = self.import_lock.lock();
|
||||||
@ -295,6 +295,10 @@ impl Client {
|
|||||||
self.report.write().unwrap().accrue_block(&block);
|
self.report.write().unwrap().accrue_block(&block);
|
||||||
trace!(target: "client", "Imported #{} ({})", header.number(), header.hash());
|
trace!(target: "client", "Imported #{} ({})", header.number(), header.hash());
|
||||||
ret += 1;
|
ret += 1;
|
||||||
|
|
||||||
|
if self.block_queue.read().unwrap().queue_info().empty {
|
||||||
|
io.send(NetworkIoMessage::User(SyncMessage::BlockVerified)).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.block_queue.write().unwrap().mark_as_good(&good_blocks);
|
self.block_queue.write().unwrap().mark_as_good(&good_blocks);
|
||||||
ret
|
ret
|
||||||
|
Loading…
Reference in New Issue
Block a user