Skip to content

Commit

Permalink
Test cleanup
Browse files Browse the repository at this point in the history
GenKey unit tests were in the benchmark suite.
  • Loading branch information
garious committed May 23, 2018
1 parent 87e025f commit d4959bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/crdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ impl Crdt {
}

#[cfg(test)]
mod test {
mod tests {
use crdt::{Crdt, ReplicatedData};
use logger;
use packet::Blob;
Expand Down
47 changes: 25 additions & 22 deletions src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>, 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()
}
}

Expand All @@ -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];
Expand All @@ -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));
}
}

0 comments on commit d4959bc

Please sign in to comment.