Skip to content

Commit 4b3bcef

Browse files
authored
test(s2n-quic-dc): add request/response tests (#2546)
1 parent 7219bbc commit 4b3bcef

File tree

3 files changed

+709
-31
lines changed

3 files changed

+709
-31
lines changed

dc/s2n-quic-dc/src/stream/testing.rs

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ pub type Reader = recv::application::Reader<Subscriber>;
2828
// limit the number of threads used in testing to reduce costs of harnesses
2929
const TEST_THREADS: usize = 2;
3030

31-
const MAX_DATAGRAM_SIZE: Option<u16> = if cfg!(target_os = "linux") {
32-
Some(8950)
31+
pub(crate) const MAX_DATAGRAM_SIZE: u16 = if cfg!(target_os = "linux") {
32+
8950
3333
} else {
34-
None
34+
1450
3535
};
3636

3737
#[derive(Clone)]
@@ -44,26 +44,15 @@ pub struct Client {
4444

4545
impl Default for Client {
4646
fn default() -> Self {
47-
let _span = tracing::info_span!("client").entered();
48-
let map = secret::map::testing::new(16);
49-
let options = socket::options::Options::new("127.0.0.1:0".parse().unwrap());
50-
let env = env::Environment::builder()
51-
.with_threads(TEST_THREADS)
52-
// TODO enable this once ready
53-
// .with_pool(env::pool::Config::new(map.clone()))
54-
.with_socket_options(options)
55-
.build()
56-
.unwrap();
57-
Self {
58-
map,
59-
env,
60-
subscriber: Arc::new(event::testing::Subscriber::no_snapshot()),
61-
mtu: MAX_DATAGRAM_SIZE,
62-
}
47+
Self::builder().build()
6348
}
6449
}
6550

6651
impl Client {
52+
pub fn builder() -> client::Builder {
53+
client::Builder::default()
54+
}
55+
6756
pub fn handshake_with<S: AsRef<server::Handle>>(
6857
&self,
6958
server: &S,
@@ -91,9 +80,7 @@ impl Client {
9180

9281
fn params(&self) -> ApplicationParams {
9382
let mut params = dc::testing::TEST_APPLICATION_PARAMS;
94-
if let Some(mtu) = self.mtu {
95-
params.max_datagram_size = mtu.into();
96-
}
83+
params.max_datagram_size = self.mtu.unwrap_or(MAX_DATAGRAM_SIZE).into();
9784
params
9885
}
9986

@@ -142,6 +129,67 @@ impl Client {
142129
}
143130
}
144131

132+
pub mod client {
133+
use super::*;
134+
135+
pub struct Builder {
136+
map_capacity: usize,
137+
mtu: Option<u16>,
138+
subscriber: event::testing::Subscriber,
139+
}
140+
141+
impl Default for Builder {
142+
fn default() -> Self {
143+
Self {
144+
map_capacity: 16,
145+
mtu: None,
146+
subscriber: event::testing::Subscriber::no_snapshot(),
147+
}
148+
}
149+
}
150+
151+
impl Builder {
152+
pub fn map_capacity(mut self, map_capacity: usize) -> Self {
153+
self.map_capacity = map_capacity;
154+
self
155+
}
156+
157+
pub fn mtu(mut self, mtu: u16) -> Self {
158+
self.mtu = Some(mtu);
159+
self
160+
}
161+
162+
pub fn subscriber(mut self, subscriber: event::testing::Subscriber) -> Self {
163+
self.subscriber = subscriber;
164+
self
165+
}
166+
167+
pub fn build(self) -> Client {
168+
let Self {
169+
map_capacity,
170+
mtu,
171+
subscriber,
172+
} = self;
173+
let _span = tracing::info_span!("client").entered();
174+
let map = secret::map::testing::new(map_capacity);
175+
let options = socket::options::Options::new("127.0.0.1:0".parse().unwrap());
176+
let env = env::Environment::builder()
177+
.with_threads(TEST_THREADS)
178+
// TODO enable this once ready
179+
// .with_pool(env::pool::Config::new(map.clone()))
180+
.with_socket_options(options)
181+
.build()
182+
.unwrap();
183+
Client {
184+
map,
185+
env,
186+
subscriber: Arc::new(subscriber),
187+
mtu,
188+
}
189+
}
190+
}
191+
}
192+
145193
#[derive(Clone)]
146194
pub struct Server {
147195
handle: server::Handle,
@@ -194,7 +242,7 @@ impl Server {
194242
}
195243
}
196244

197-
mod drop_handle {
245+
pub(crate) mod drop_handle {
198246
use core::future::Future;
199247
use tokio::sync::watch;
200248

@@ -241,9 +289,7 @@ pub mod server {
241289
impl Handle {
242290
pub(super) fn params(&self) -> ApplicationParams {
243291
let mut params = dc::testing::TEST_APPLICATION_PARAMS;
244-
if let Some(mtu) = self.mtu {
245-
params.max_datagram_size = mtu.into();
246-
}
292+
params.max_datagram_size = self.mtu.unwrap_or(MAX_DATAGRAM_SIZE).into();
247293
params
248294
}
249295
}
@@ -418,11 +464,7 @@ pub mod server {
418464
map,
419465
protocol,
420466
local_addr,
421-
mtu: if let Some(mtu) = mtu {
422-
Some(mtu)
423-
} else {
424-
MAX_DATAGRAM_SIZE
425-
},
467+
mtu,
426468
};
427469

428470
super::Server {

dc/s2n-quic-dc/src/stream/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
mod accept_queue;
55
mod key_update;
6+
mod request_response;

0 commit comments

Comments
 (0)