Commit 967ea67b authored by Nick Mathewson's avatar Nick Mathewson 🐚
Browse files

Use testing_rng() in tests throughout our crates.

This only affects uses of thread_rng(), and affects them all more or
less indiscriminately.  One test does not work with
ARTI_TEST_PRNG=deterministic; the next commit will fix it.
parent 69d352a7
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -3617,6 +3617,7 @@ dependencies = [
 "simple_asn1",
 "subtle",
 "thiserror",
 "tor-basic-utils",
 "x25519-dalek",
 "zeroize",
]
@@ -3636,6 +3637,7 @@ dependencies = [
 "serde",
 "signature",
 "thiserror",
 "tor-basic-utils",
 "tor-checkable",
 "tor-config",
 "tor-linkspec",
@@ -3767,6 +3769,7 @@ dependencies = [
 "pin-project",
 "rand 0.8.5",
 "thiserror",
 "tor-basic-utils",
 "tor-rtcompat",
 "tracing",
]
+2 −1
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ impl Default for RetryDelay {
#[cfg(test)]
mod test {
    use super::*;
    use crate::test_rng::testing_rng;

    #[test]
    fn init() {
@@ -152,7 +153,7 @@ mod test {
        let mut rd = RetryDelay::from_msec(50);
        let real_low_bound = std::cmp::max(50, MIN_LOW_BOUND);

        let mut rng = rand::thread_rng();
        let mut rng = testing_rng();
        for _ in 1..100 {
            let (b_lo, b_hi) = rd.delay_bounds();
            assert!(b_lo == real_low_bound);
+2 −1
Original line number Diff line number Diff line
use tor_basic_utils::test_rng::testing_rng;
use tor_bytes::Error as BytesError;
/// Example relay messages to encode and decode.
///
@@ -465,7 +466,7 @@ fn test_data() {
    // Try creating a data cell from too much data.
    use rand::RngCore;
    let mut b = vec![0_u8; 3000];
    rand::thread_rng().fill_bytes(&mut b[..]);
    testing_rng().fill_bytes(&mut b[..]);
    let d = msg::Data::new(&b[..]);
    assert!(d.is_err());

+5 −4
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ mod test {
    use crate::path::assert_same_path_when_owned;
    use crate::test::OptDummyGuardMgr;
    use std::collections::HashSet;
    use tor_basic_utils::test_rng::testing_rng;
    use tor_guardmgr::fallback::{FallbackDir, FallbackList};
    use tor_linkspec::ChanTarget;
    use tor_netdir::testnet;
@@ -96,7 +97,7 @@ mod test {
            .unwrap()
            .unwrap_if_sufficient()
            .unwrap();
        let mut rng = rand::thread_rng();
        let mut rng = testing_rng();
        let dirinfo = (&netdir).into();
        let guards: OptDummyGuardMgr<'_> = None;

@@ -136,7 +137,7 @@ mod test {
        ];
        let fb: FallbackList = fb_owned.clone().into();
        let dirinfo = (&fb).into();
        let mut rng = rand::thread_rng();
        let mut rng = testing_rng();
        let guards: OptDummyGuardMgr<'_> = None;

        for _ in 0..10 {
@@ -158,7 +159,7 @@ mod test {
    fn dirpath_no_fallbacks() {
        let fb = FallbackList::from([]);
        let dirinfo = DirInfo::Fallbacks(&fb);
        let mut rng = rand::thread_rng();
        let mut rng = testing_rng();
        let guards: OptDummyGuardMgr<'_> = None;

        let err = DirPathBuilder::default().pick_path(&mut rng, dirinfo, guards);
@@ -178,7 +179,7 @@ mod test {
                .unwrap()
                .unwrap_if_sufficient()
                .unwrap();
            let mut rng = rand::thread_rng();
            let mut rng = testing_rng();
            let dirinfo = (&netdir).into();
            let statemgr = tor_persist::TestingStateMgr::new();
            let guards = tor_guardmgr::GuardMgr::new(rt.clone(), statemgr, [].into()).unwrap();
+5 −4
Original line number Diff line number Diff line
@@ -237,6 +237,7 @@ mod test {
    use crate::path::{assert_same_path_when_owned, OwnedPath, TorPathInner};
    use crate::test::OptDummyGuardMgr;
    use std::collections::HashSet;
    use tor_basic_utils::test_rng::testing_rng;
    use tor_linkspec::ChanTarget;
    use tor_netdir::testnet;
    use tor_rtcompat::SleepProvider;
@@ -262,7 +263,7 @@ mod test {

    #[test]
    fn by_ports() {
        let mut rng = rand::thread_rng();
        let mut rng = testing_rng();
        let netdir = testnet::construct_netdir()
            .unwrap()
            .unwrap_if_sufficient()
@@ -309,7 +310,7 @@ mod test {

    #[test]
    fn any_exit() {
        let mut rng = rand::thread_rng();
        let mut rng = testing_rng();
        let netdir = testnet::construct_netdir()
            .unwrap()
            .unwrap_if_sufficient()
@@ -359,7 +360,7 @@ mod test {
        .unwrap()
        .unwrap_if_sufficient()
        .unwrap();
        let mut rng = rand::thread_rng();
        let mut rng = testing_rng();
        let dirinfo = (&netdir).into();
        let guards: OptDummyGuardMgr<'_> = None;
        let config = PathConfig::default();
@@ -392,7 +393,7 @@ mod test {
                .unwrap()
                .unwrap_if_sufficient()
                .unwrap();
            let mut rng = rand::thread_rng();
            let mut rng = testing_rng();
            let dirinfo = (&netdir).into();
            let statemgr = tor_persist::TestingStateMgr::new();
            let guards = tor_guardmgr::GuardMgr::new(rt.clone(), statemgr, [].into()).unwrap();
Loading