Skip to content

Commit

Permalink
Bump rand to v0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini committed Jan 27, 2025
1 parent 954e4c7 commit 8c49781
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ indexmap = "2.0.2"
lazy_static = "1.4.0"
pin-project-lite = "0.2.7"
quickcheck = "1"
rand = "0.8"
rand = "0.9"
slab = "0.4"
sync_wrapper = "1"
tokio = "1.6.2"
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2018"
tower = { version = "0.4", path = "../tower", features = ["full"] }
tower-service = "0.3"
tokio = { version = "1.0", features = ["full"] }
rand = "0.8"
rand = "0.9"
pin-project = "1.0"
futures = "0.3.22"
tracing = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion tower/examples/tower-balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn gen_disco() -> impl Discover<

let maxms = u64::from(latency.subsec_millis())
.saturating_add(latency.as_secs().saturating_mul(1_000));
let latency = Duration::from_millis(rand::thread_rng().gen_range(0..maxms));
let latency = Duration::from_millis(rand::rng().random_range(0..maxms));

async move {
time::sleep_until(start + latency).await;
Expand Down
13 changes: 10 additions & 3 deletions tower/tests/balance/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#[path = "../support.rs"]
mod support;

use rand::distr::{Distribution, Uniform};
use std::future::Future;
use std::task::{Context, Poll};
use tokio_test::{assert_pending, assert_ready, task};
Expand All @@ -28,7 +29,9 @@ impl Service<Req> for Mock {
impl tower::load::Load for Mock {
type Metric = usize;
fn load(&self) -> Self::Metric {
rand::random()
Uniform::new_inclusive(usize::MIN, usize::MAX)
.unwrap()
.sample(&mut rand::rng())
}
}

Expand Down Expand Up @@ -114,7 +117,9 @@ fn stress() {
} else {
// remove
while !services.is_empty() {
let k = rand::random::<usize>() % (services.iter().last().unwrap().0 + 1);
let k = Uniform::new_inclusive(0, services.iter().last().unwrap().0)
.unwrap()
.sample(&mut rand::rng());
if services.contains(k) {
let (handle, ready) = services.remove(k);
if ready {
Expand All @@ -129,7 +134,9 @@ fn stress() {
} else {
// fail a service
while !services.is_empty() {
let k = rand::random::<usize>() % (services.iter().last().unwrap().0 + 1);
let k = Uniform::new_inclusive(0, services.iter().last().unwrap().0)
.unwrap()
.sample(&mut rand::rng());
if services.contains(k) {
let (mut handle, ready) = services.remove(k);
if ready {
Expand Down

0 comments on commit 8c49781

Please sign in to comment.