Skip to content

Commit d88faa4

Browse files
authored
build(deps): bach and rand updates (#2502)
1 parent db0a622 commit d88faa4

File tree

9 files changed

+36
-31
lines changed

9 files changed

+36
-31
lines changed

quic/s2n-quic-platform/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tokio-runtime = ["futures", "tokio"]
2020
xdp = ["s2n-quic-xdp"]
2121

2222
[dependencies]
23-
bach = { version = "0.0.6", optional = true }
23+
bach = { version = "0.0.10", optional = true }
2424
bolero-generator = { version = "0.13", default-features = false, optional = true }
2525
cfg-if = "1"
2626
futures = { version = "0.3", default-features = false, features = ["async-await"], optional = true }
@@ -36,7 +36,7 @@ turmoil = { version = "0.6.0", optional = true }
3636
libc = "0.2"
3737

3838
[dev-dependencies]
39-
bach = { version = "0.0.6" }
39+
bach = { version = "0.0.10" }
4040
bolero = "0.13"
4141
bolero-generator = "0.13"
4242
futures = { version = "0.3", features = ["std"] }

quic/s2n-quic-platform/src/io/testing.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use bach::time::scheduler;
4+
use bach::{environment::Macrostep, time::scheduler};
55
use core::task::Poll;
66
use s2n_quic_core::{
77
endpoint::Endpoint, inet::SocketAddress, io::event_loop::EventLoop, path::mtu,
@@ -42,7 +42,7 @@ pub mod rand {
4242

4343
#[inline]
4444
fn gen_bool(&mut self) -> bool {
45-
gen()
45+
produce::<bool>().any()
4646
}
4747

4848
#[inline]
@@ -52,7 +52,7 @@ pub mod rand {
5252

5353
#[inline]
5454
fn gen_range(&mut self, range: core::ops::Range<u64>) -> u64 {
55-
gen_range(range)
55+
range.any()
5656
}
5757
}
5858
}
@@ -90,7 +90,7 @@ impl<N: Network> Executor<N> {
9090
}
9191

9292
pub fn enter<F: FnOnce() -> O, O>(&mut self, f: F) -> O {
93-
self.executor.environment().enter(f)
93+
bach::environment::Environment::enter(self.executor.environment(), f)
9494
}
9595

9696
pub fn run(&mut self) {
@@ -100,7 +100,7 @@ impl<N: Network> Executor<N> {
100100
pub fn close(&mut self) {
101101
// close the environment, which notifies all of the tasks that we're shutting down
102102
self.executor.environment().close(|| {});
103-
while self.executor.macrostep() > 0 {}
103+
while self.executor.macrostep().tasks > 0 {}
104104

105105
// then close the actual executor
106106
self.executor.close()
@@ -123,10 +123,6 @@ struct Env<N> {
123123
}
124124

125125
impl<N> Env<N> {
126-
fn enter<F: FnOnce() -> O, O>(&self, f: F) -> O {
127-
self.handle.enter(|| self.time.enter(|| self.rand.enter(f)))
128-
}
129-
130126
fn close<F: FnOnce()>(&mut self, f: F) {
131127
let handle = &mut self.handle;
132128
let rand = &mut self.rand;
@@ -144,11 +140,15 @@ impl<N> Env<N> {
144140
}
145141
}
146142

147-
impl<N: Network> bach::executor::Environment for Env<N> {
148-
fn run<Tasks, F>(&mut self, tasks: Tasks) -> Poll<()>
143+
impl<N: Network> bach::environment::Environment for Env<N> {
144+
fn enter<F: FnOnce() -> O, O>(&mut self, f: F) -> O {
145+
self.handle.enter(|| self.time.enter(|| self.rand.enter(f)))
146+
}
147+
148+
fn run<Tasks, R>(&mut self, tasks: Tasks) -> Poll<()>
149149
where
150-
Tasks: Iterator<Item = F> + Send,
151-
F: 'static + FnOnce() -> Poll<()> + Send,
150+
Tasks: IntoIterator<Item = R>,
151+
R: bach::environment::Runnable,
152152
{
153153
let mut is_ready = true;
154154

@@ -165,7 +165,7 @@ impl<N: Network> bach::executor::Environment for Env<N> {
165165
time.enter(|| {
166166
rand.enter(|| {
167167
for task in tasks {
168-
is_ready &= task().is_ready();
168+
is_ready &= task.run().is_ready();
169169
}
170170
network.execute(buffers);
171171
})
@@ -179,11 +179,11 @@ impl<N: Network> bach::executor::Environment for Env<N> {
179179
}
180180
}
181181

182-
fn on_macrostep(&mut self, count: usize) {
182+
fn on_macrostep(&mut self, macrostep: Macrostep) -> Macrostep {
183183
// only advance time after a stall
184-
if count > 0 {
184+
if macrostep.tasks > 0 {
185185
self.stalled_iterations = 0;
186-
return;
186+
return macrostep;
187187
}
188188

189189
self.stalled_iterations += 1;
@@ -206,6 +206,7 @@ impl<N: Network> bach::executor::Environment for Env<N> {
206206
break;
207207
}
208208
}
209+
macrostep
209210
}
210211

211212
fn close<F>(&mut self, close: F)

quic/s2n-quic-platform/src/io/testing/model.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use super::network::{Buffers, Network, Packet};
4+
use super::{
5+
network::{Buffers, Network, Packet},
6+
rand::Any,
7+
};
58
use core::time::Duration;
69
use s2n_quic_core::{havoc, path::MaxMtu};
710
use std::{
@@ -241,7 +244,7 @@ impl Network for Model {
241244
#[inline]
242245
fn gen_rate(rate: u64) -> bool {
243246
// ensure the rate isn't 0 before actually generating a random number
244-
rate > 0 && super::rand::gen::<u64>() < rate
247+
rate > 0 && super::rand::produce::<u64>().any() < rate
245248
}
246249

247250
let mut transmit = |packet: Cow<Packet>| {
@@ -360,7 +363,7 @@ impl Network for Model {
360363
}
361364

362365
fn gen_jitter(max_jitter: Duration) -> Duration {
363-
let micros = super::rand::gen_range(0..max_jitter.as_micros() as u64);
366+
let micros = Any::any(&(0..max_jitter.as_micros() as u64));
364367
let micros = micros as f64;
365368
// even though we're generated micros, we round to the nearest millisecond
366369
// so packets can be grouped together

quic/s2n-quic-platform/src/io/testing/time.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use core::{
1111
use s2n_quic_core::time::{clock, Timestamp};
1212

1313
pub fn now() -> Timestamp {
14-
unsafe { Timestamp::from_duration(time::now()) }
14+
unsafe { Timestamp::from_duration(time::Instant::now().elapsed_since_start()) }
1515
}
1616

1717
pub fn delay(duration: Duration) -> Timer {

quic/s2n-quic-sim/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ publish = false
1313
[dependencies]
1414
anyhow = "1"
1515
bytes = "1"
16+
bolero-generator = "0.13.0"
1617
humantime = "2"
1718
indicatif = { version = "0.17", features = ["rayon"] }
1819
once_cell = "1"
1920
prost = "0.13"
20-
rand = "0.8"
21+
rand = "0.9"
2122
rayon = "1"
2223
s2n-quic = { path = "../s2n-quic", features = ["unstable-provider-io-testing", "provider-event-tracing"] }
2324
s2n-quic-core = { path = "../s2n-quic-core", features = ["testing"] }

quic/s2n-quic-sim/src/run.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl Run {
108108
.while_some()
109109
.for_each(|_| {
110110
use ::rand::prelude::*;
111-
let seed = thread_rng().gen();
111+
let seed = rand::rng().random();
112112
test(seed);
113113
});
114114
} else {

quic/s2n-quic-sim/src/run/endpoint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn client(
6060
total_delay += delay.gen_duration();
6161

6262
// pick a random server to connect to
63-
let server_addr = *rand::one_of(servers);
63+
let server_addr = *rand::pick(servers);
6464
let delay = total_delay;
6565

6666
let client = client.clone();

quic/s2n-quic-sim/src/run/range.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ impl<T: PartialEq + fmt::Display> fmt::Display for CliRange<T> {
4747

4848
impl<T> CliRange<T>
4949
where
50-
T: Copy + PartialOrd + ::rand::distributions::uniform::SampleUniform,
50+
T: Copy + PartialOrd + ::bolero_generator::bounded::BoundedValue,
5151
{
5252
pub fn gen(&self) -> T {
5353
if self.start == self.end {
5454
return self.start;
5555
}
5656

57-
rand::gen_range(self.start..self.end)
57+
rand::Any::any(&(self.start..self.end))
5858
}
5959
}
6060

@@ -67,7 +67,7 @@ impl CliRange<humantime::Duration> {
6767
return Duration::from_nanos(start as _);
6868
}
6969

70-
let nanos = rand::gen_range(start..end);
70+
let nanos = rand::Any::any(&(start..end));
7171
Duration::from_nanos(nanos as _)
7272
}
7373
}

quic/s2n-quic/src/tests/issue_1427.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use super::*;
4+
use super::{rand::Any, *};
55
use tokio::io::{AsyncReadExt, AsyncWriteExt};
66

77
/// Ensures tokio `AsyncRead` implementation functions properly
@@ -31,7 +31,7 @@ fn tokio_read_exact_test() {
3131
while read_len < LEN {
3232
let max_len = buf.len().min(LEN - read_len);
3333
// generate a random amount of bytes to read
34-
let len = rand::gen_range(1..=max_len);
34+
let len = Any::any(&(1..=max_len));
3535

3636
let buf = &mut buf[0..len];
3737
recv.read_exact(buf).await.unwrap();

0 commit comments

Comments
 (0)