queue: verifier scaling tests

This commit is contained in:
Robert Habermeier 2016-11-21 14:23:34 +01:00
parent 8c0e511ebe
commit 133796b7ff

View File

@ -574,8 +574,12 @@ impl<K: Kind> VerificationQueue<K> {
pub fn collect_garbage(&self) { pub fn collect_garbage(&self) {
// number of ticks to average queue stats over // number of ticks to average queue stats over
// when deciding whether to change the number of verifiers. // when deciding whether to change the number of verifiers.
#[cfg(not(test))]
const READJUSTMENT_PERIOD: usize = 12; const READJUSTMENT_PERIOD: usize = 12;
#[cfg(test)]
const READJUSTMENT_PERIOD: usize = 1;
let (u_len, v_len) = { let (u_len, v_len) = {
let u_len = { let u_len = {
let mut q = self.verification.unverified.lock(); let mut q = self.verification.unverified.lock();
@ -595,10 +599,9 @@ impl<K: Kind> VerificationQueue<K> {
self.processing.write().shrink_to_fit(); self.processing.write().shrink_to_fit();
if self.ticks_since_adjustment.load(AtomicOrdering::SeqCst) == READJUSTMENT_PERIOD { if self.ticks_since_adjustment.fetch_add(1, AtomicOrdering::SeqCst) + 1 >= READJUSTMENT_PERIOD {
self.ticks_since_adjustment.store(0, AtomicOrdering::SeqCst); self.ticks_since_adjustment.store(0, AtomicOrdering::SeqCst);
} else { } else {
self.ticks_since_adjustment.fetch_add(1, AtomicOrdering::SeqCst);
return; return;
} }
@ -627,7 +630,7 @@ impl<K: Kind> VerificationQueue<K> {
let mut verifiers = self.verifiers.lock(); let mut verifiers = self.verifiers.lock();
let &mut (ref mut verifiers, ref mut verifier_count) = &mut *verifiers; let &mut (ref mut verifiers, ref mut verifier_count) = &mut *verifiers;
let target = min(verifiers.capacity(), target); let target = min(verifiers.len(), target);
let target = max(1, target); let target = max(1, target);
debug!(target: "verification", "Scaling from {} to {} verifiers", verifier_count, target); debug!(target: "verification", "Scaling from {} to {} verifiers", verifier_count, target);
@ -774,4 +777,56 @@ mod tests {
} }
assert!(queue.queue_info().is_full()); assert!(queue.queue_info().is_full());
} }
#[test]
fn scaling_limits() {
use super::MAX_VERIFIERS;
let queue = get_test_queue();
queue.scale_verifiers(MAX_VERIFIERS + 1);
assert!(queue.verifiers.lock().1 < MAX_VERIFIERS + 1);
queue.scale_verifiers(0);
assert!(queue.verifiers.lock().1 == 1);
}
#[test]
fn readjust_verifiers() {
let queue = get_test_queue();
// put all the verifiers to sleep to ensure
// the test isn't timing sensitive.
let num_verifiers = {
let verifiers = queue.verifiers.lock();
for i in 0..verifiers.1 {
verifiers.0[i].sleep();
}
verifiers.1
};
for block in get_good_dummy_block_seq(5000) {
queue.import(Unverified::new(block)).expect("Block good by definition; qed");
}
// almost all unverified == bump verifier count.
queue.collect_garbage();
assert_eq!(queue.verifiers.lock().1, num_verifiers + 1);
// wake them up again and verify everything.
{
let verifiers = queue.verifiers.lock();
for i in 0..verifiers.1 {
verifiers.0[i].wake_up();
}
}
queue.flush();
// nothing to verify == use minimum number of verifiers.
queue.collect_garbage();
assert_eq!(queue.verifiers.lock().1, 1);
}
} }