use a fixed seed

This commit is contained in:
Niko Matsakis 2019-07-02 06:34:37 -04:00
parent 7bd9e0120f
commit ed2bd527e8
2 changed files with 6 additions and 12 deletions

View file

@ -1,6 +1,5 @@
use parking_lot::Mutex;
use rand::rngs::SmallRng;
use rand::FromEntropy;
use rand::Rng;
use rand::SeedableRng;
use std::fmt::Debug;
@ -58,16 +57,17 @@ where
}
}
// We always use a fixed seed for our randomness so that we have
// predictable results.
const LRU_SEED: &str = "Hello, Rustaceans";
impl<Node> Lru<Node>
where
Node: LruNode,
{
/// Creates a new LRU list where LRU caching is disabled.
pub fn new() -> Self {
Lru {
green_zone: AtomicUsize::new(0),
data: Mutex::new(LruData::new()),
}
Self::with_seed(LRU_SEED)
}
#[cfg_attr(not(test), allow(dead_code))]
@ -137,11 +137,6 @@ impl<Node> LruData<Node>
where
Node: LruNode,
{
fn new() -> Self {
Self::with_rng(SmallRng::from_entropy())
}
#[cfg_attr(not(test), allow(dead_code))]
fn with_seed(seed_str: &str) -> Self {
Self::with_rng(rng_with_seed(seed_str))
}

View file

@ -25,7 +25,6 @@ impl LruNode for TestNode {
}
}
const LRU_SEED: &str = "Hello, Rustaceans";
const PICK_SEED: &str = "Wippity WIP";
/// Randomly requests nodes and compares the performance of a
@ -48,7 +47,7 @@ fn compare(
// it. When the capacity is exceed, we can pop the oldest.
let mut oracle = LinkedHashMap::new();
let lru = Lru::with_seed(LRU_SEED);
let lru = Lru::with_seed(super::LRU_SEED);
lru.set_lru_capacity(capacity);
let nodes: Vec<_> = (0..num_nodes).map(|i| TestNode::new(i)).collect();