From d4959bc157e9e02ae5e0484b9ae578181c25c227 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Wed, 23 May 2018 12:23:39 -0600 Subject: [PATCH] Test cleanup GenKey unit tests were in the benchmark suite. --- src/crdt.rs | 2 +- src/signature.rs | 47 +++++++++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/crdt.rs b/src/crdt.rs index eef6981f4720dd..1393fb5a53828e 100644 --- a/src/crdt.rs +++ b/src/crdt.rs @@ -502,7 +502,7 @@ impl Crdt { } #[cfg(test)] -mod test { +mod tests { use crdt::{Crdt, ReplicatedData}; use logger; use packet::Blob; diff --git a/src/signature.rs b/src/signature.rs index 0bb704f8000b17..1521f815f4af6b 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -72,27 +72,23 @@ impl GenKeys { pub fn gen_n_seeds(&self, n_seeds: i64) -> Vec<[u8; 16]> { let mut rng = self.generator.borrow_mut(); - let seeds = (0..n_seeds) + (0..n_seeds) .into_iter() - .map(|_| { - let seed: [u8; 16] = rng.gen(); - seed - }) - .collect(); - seeds + .map(|_| rng.gen::<[u8; 16]>()) + .collect() } pub fn gen_n_keys(&self, n_keys: i64, tokens_per_user: i64) -> Vec<(Vec, i64)> { - let keys = self.gen_n_seeds(n_keys); + let seeds = self.gen_n_seeds(n_keys); - let users: Vec<_> = keys.into_par_iter() + seeds + .into_par_iter() .map(|seed| { let new: GenKeys = GenKeys::new(&seed[..]); let pkcs8 = KeyPair::generate_pkcs8(&new).unwrap().to_vec(); (pkcs8, tokens_per_user) }) - .collect(); - users + .collect() } } @@ -104,22 +100,12 @@ impl SecureRandom for GenKeys { } } -#[cfg(all(feature = "unstable", test))] +#[cfg(test)] mod tests { - extern crate test; - - use self::test::Bencher; use super::*; use std::collections::HashSet; use std::iter::FromIterator; - #[bench] - fn bench_gen_keys(b: &mut Bencher) { - let seed: &[_] = &[1, 2, 3, 4]; - let rnd = GenKeys::new(seed); - b.iter(|| rnd.gen_n_keys(1000, 1)); - } - #[test] fn test_new_key_is_redundant() { let seed: &[_] = &[1, 2, 3, 4]; @@ -145,3 +131,20 @@ mod tests { assert_eq!(users1_set, users2_set); } } + +#[cfg(all(feature = "unstable", test))] +mod bench { + extern crate test; + + use self::test::Bencher; + use super::*; + use std::collections::HashSet; + use std::iter::FromIterator; + + #[bench] + fn bench_gen_keys(b: &mut Bencher) { + let seed: &[_] = &[1, 2, 3, 4]; + let rnd = GenKeys::new(seed); + b.iter(|| rnd.gen_n_keys(1000, 1)); + } +}