diff --git a/Cargo.lock b/Cargo.lock index d520e15b78..6e53f3df18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2605,6 +2605,7 @@ dependencies = [ "postcard", "quic-rpc", "rand", + "rand_xorshift", "ratatui", "regex", "reqwest 0.12.5", diff --git a/iroh-cli/Cargo.toml b/iroh-cli/Cargo.toml index 1615b59bc2..f77daa5ddb 100644 --- a/iroh-cli/Cargo.toml +++ b/iroh-cli/Cargo.toml @@ -69,6 +69,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] } [dev-dependencies] duct = "0.13.6" nix = { version = "0.27", features = ["signal", "process"] } +rand_xorshift = "0.3.0" regex = "1.10.3" testdir = "0.9.1" walkdir = "2" diff --git a/iroh-cli/tests/cli.rs b/iroh-cli/tests/cli.rs index ae6f2993a0..8bb6735df2 100644 --- a/iroh-cli/tests/cli.rs +++ b/iroh-cli/tests/cli.rs @@ -15,17 +15,27 @@ use iroh::{ blobs::{Hash, HashAndFormat}, util::path::IrohPaths, }; -use rand::distributions::{Alphanumeric, DistString}; -use rand::SeedableRng; +use rand::{RngCore, SeedableRng}; use regex::Regex; use testdir::testdir; use walkdir::WalkDir; fn make_rand_file(size: usize, path: &Path) -> Result { - let mut rng = rand::rngs::StdRng::seed_from_u64(1); - let content = Alphanumeric.sample_string(&mut rng, size); + // 64 chars makes for easy random sampling + const CHARS_LUT: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\ + abcdefghijklmnopqrstuvwxyz\ + 0123456789 ."; + + // We do something custom to eek out a little bit more performance + // over just a simple `rand::distributions::Alphanumeric.sample_string`. + let mut rng = rand_xorshift::XorShiftRng::seed_from_u64(1); + let content = std::iter::from_fn(move || Some(rng.next_u32())) + .flat_map(u32::to_le_bytes) + .map(|num| CHARS_LUT[(num >> (8 - 6)) as usize]) + .take(size) + .collect::>(); - let hash = blake3::hash(content.as_bytes()); + let hash = blake3::hash(&content); std::fs::write(path, content)?; Ok(hash.into()) } @@ -904,7 +914,7 @@ fn match_get_stderr(stderr: Vec) -> Result)>> { (r"", 1), (r"Fetching: [\da-z]{52}", 1), ( - r"Transferred (\d*.?\d*? ?[BKMGT]i?B?) in \d* seconds?, \d*.?\d* ?(?:B|KiB|MiB|GiB|TiB)/s", + r"Transferred (\d*.?\d*? ?[BKMGT]i?B?) in \d* (second|minute)s?, \d*.?\d* ?(?:B|KiB|MiB|GiB|TiB)/s", 1, ), ],