Skip to content

Commit 1f29d59

Browse files
authored
test(s2n-quic-dc): disable tracing by default for tests with large output (#2571)
1 parent d31522c commit 1f29d59

File tree

5 files changed

+115
-70
lines changed

5 files changed

+115
-70
lines changed

dc/s2n-quic-dc/src/path/secret/map/cleaner.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ impl Cleaner {
6060
C: 'static + time::Clock + Send + Sync,
6161
S: event::Subscriber,
6262
{
63+
// check to see if we're in a simulation before spawning a thread
64+
#[cfg(any(test, feature = "testing"))]
65+
if bach::is_active() {
66+
return;
67+
}
68+
6369
let state = Arc::downgrade(&state);
6470
let handle = std::thread::Builder::new()
6571
.name("dc_quic::cleaner".into())

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,15 @@ macro_rules! negative_suite {
270270

271271
macro_rules! current_thread {
272272
($name:ident, $protocol:expr, $buffer_len:expr, $iterations:expr, $features:expr) => {
273-
#[tokio::test]
274-
async fn $name() {
275-
run($protocol, $buffer_len, $iterations, $features).await;
273+
#[test]
274+
fn $name() {
275+
crate::testing::without_tracing(|| {
276+
let rt = tokio::runtime::Builder::new_current_thread()
277+
.enable_all()
278+
.build()
279+
.unwrap();
280+
rt.block_on(run($protocol, $buffer_len, $iterations, $features));
281+
});
276282
}
277283
};
278284
}
@@ -281,6 +287,8 @@ macro_rules! multi_thread {
281287
($name:ident, $protocol:expr, $buffer_len:expr, $iterations:expr, $features:expr) => {
282288
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
283289
async fn $name() {
290+
// Since these run different threads, it's not super easy to use the `without_tracing` function.
291+
// Hopefully that will be ok for the CI with limited memory.
284292
run($protocol, $buffer_len, $iterations, $features).await;
285293
}
286294
};
@@ -290,12 +298,14 @@ macro_rules! sim {
290298
($name:ident, $protocol:expr, $buffer_len:expr, $iterations:expr, $features:expr) => {
291299
#[test]
292300
fn $name() {
293-
crate::testing::sim(|| {
294-
async {
295-
run($protocol, $buffer_len, $iterations, $features).await;
296-
}
297-
.primary()
298-
.spawn();
301+
crate::testing::without_tracing(|| {
302+
crate::testing::sim(|| {
303+
async {
304+
run($protocol, $buffer_len, $iterations, $features).await;
305+
}
306+
.primary()
307+
.spawn();
308+
});
299309
});
300310
}
301311
};

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ pub type Stream = application::Stream<Subscriber>;
3434
pub type Writer = send::application::Writer<Subscriber>;
3535
pub type Reader = recv::application::Reader<Subscriber>;
3636

37-
// TODO enable this once ready
38-
const DEFAULT_POOLED: bool = false;
37+
const DEFAULT_POOLED: bool = true;
3938

4039
// limit the number of threads used in testing to reduce costs of harnesses
4140
const TEST_THREADS: usize = 2;
@@ -398,7 +397,7 @@ pub mod server {
398397
impl Default for Builder {
399398
fn default() -> Self {
400399
Self {
401-
backlog: 16,
400+
backlog: 4096,
402401
flavor: accept::Flavor::default(),
403402
protocol: Protocol::Tcp,
404403
map_capacity: 16,

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

Lines changed: 69 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
socket::Protocol,
77
testing::{self, Stream, MAX_DATAGRAM_SIZE},
88
},
9-
testing::{ext::*, sim, sleep, spawn, task::spawn_named, timeout},
9+
testing::{ext::*, sim, sleep, spawn, task::spawn_named, timeout, without_tracing},
1010
};
1111
use bolero::{produce, TypeGenerator, ValueGenerator as _};
1212
use core::time::Duration;
@@ -186,9 +186,9 @@ async fn check_read(
186186
let offset = data.offset();
187187
let capacity = data.buffered_len();
188188
let mut data = data.with_write_limit(capacity.min(max_read_len));
189-
tracing::info!(offset, capacity = data.remaining_capacity(), "read_into");
189+
tracing::debug!(offset, capacity = data.remaining_capacity(), "read_into");
190190
let len = stream.read_into(&mut data).await?;
191-
tracing::info!(len, "read_into_result");
191+
tracing::debug!(len, "read_into_result");
192192
if len == 0 {
193193
break;
194194
}
@@ -203,13 +203,13 @@ async fn check_write(stream: &mut Stream, delays: &Delays, amount: usize) -> io:
203203
info!(writing = amount);
204204
let mut data = Data::new(amount as _);
205205
while !data.is_finished() {
206-
tracing::info!(
206+
tracing::debug!(
207207
offset = data.offset(),
208208
remaining = data.buffered_len(),
209209
"write_from"
210210
);
211211
let len = stream.write_from(&mut data).await?;
212-
tracing::info!(len, "write_from_result");
212+
tracing::debug!(len, "write_from_result");
213213
}
214214
info!(amount, "write_from_finished");
215215
Ok(())
@@ -356,15 +356,19 @@ impl Harness {
356356
}
357357

358358
if is_sim {
359-
// TODO limit concurrency
359+
// TODO limit concurrency - for now we just stagger clients
360360

361361
for idx in 0..self.client.count {
362362
let config = self.client;
363363
let requests = requests.clone();
364364
let client = client.clone();
365365
let server = server.clone();
366366
let task = async move {
367+
// delay connecting by 1us per client
368+
(1.us() * idx as u32).sleep().await;
369+
367370
info!("connecting");
371+
368372
let stream = client.connect_to(&server).await.unwrap();
369373
info!(peer_addr = %stream.peer_addr().unwrap(), local_addr = %stream.local_addr().unwrap());
370374

@@ -429,8 +433,8 @@ struct Runtime {
429433
}
430434

431435
impl Runtime {
432-
fn new(harness: Harness) -> Self {
433-
let rt = tokio::runtime::Builder::new_multi_thread()
436+
fn new(harness: &Harness) -> Self {
437+
let rt = tokio::runtime::Builder::new_current_thread()
434438
.enable_all()
435439
.build()
436440
.unwrap();
@@ -452,6 +456,10 @@ impl Runtime {
452456
}
453457
}
454458

459+
fn run(&self, harness: Harness) {
460+
self.rt.block_on(harness.run());
461+
}
462+
455463
fn run_with(&self, client: Client, server: Server, requests: Vec<Request>) {
456464
let harness = Harness {
457465
client,
@@ -528,11 +536,6 @@ macro_rules! tests {
528536
$test!(multi_request_test, {
529537
let harness = harness();
530538

531-
// TODO make this not flaky with UDP
532-
if harness.protocol.is_udp() {
533-
return;
534-
}
535-
536539
Harness {
537540
requests: vec![Request {
538541
count: 10,
@@ -628,46 +631,54 @@ macro_rules! tests {
628631

629632
macro_rules! tokio_test {
630633
($name:ident, $harness:expr) => {
631-
#[tokio::test]
632-
async fn $name() {
633-
$harness.run().await;
634+
#[test]
635+
fn $name() {
636+
let harness = $harness;
637+
without_tracing(|| {
638+
Runtime::new(&harness).run(harness);
639+
});
634640
}
635641
};
636642
}
637643

638644
macro_rules! tokio_fuzz_test {
639645
() => {
640646
#[test]
641-
#[ignore = "TODO the CI currently doesn't like running these tests - need to figure out why"]
642647
fn fuzz_test() {
643-
use std::sync::OnceLock;
644-
645-
bolero::check!()
646-
.with_generator((produce(), produce(), produce::<Vec<_>>().with().len(1..5)))
647-
.cloned()
648-
.with_test_time(Duration::from_secs(45))
649-
.for_each(|(client, server, requests)| {
650-
static RUNTIME: OnceLock<Runtime> = OnceLock::new();
651-
RUNTIME
652-
.get_or_init(|| Runtime::new(harness()))
653-
.run_with(client, server, requests);
654-
});
648+
without_tracing(|| {
649+
use std::sync::OnceLock;
650+
651+
bolero::check!()
652+
.with_generator((produce(), produce(), produce::<Vec<_>>().with().len(1..5)))
653+
.cloned()
654+
// limit the amount of time in tests since they can produce a log of tracing data
655+
.with_test_time(Duration::from_secs(10))
656+
.for_each(|(client, server, requests)| {
657+
static RUNTIME: OnceLock<Runtime> = OnceLock::new();
658+
RUNTIME
659+
.get_or_init(|| Runtime::new(&harness()))
660+
.run_with(client, server, requests);
661+
});
662+
});
655663
}
656-
}
664+
};
657665
}
658666

659667
macro_rules! sim_test {
660668
($name:ident, $harness:expr) => {
661669
#[test]
662670
fn $name() {
663-
sim(|| {
664-
spawn_named($harness.run().primary(), "harness");
665-
666-
async {
667-
sleep(Duration::from_secs(120)).await;
668-
panic!("test timed out after {}", bach::time::Instant::now());
669-
}
670-
.spawn();
671+
// The tracing logs end up consuming a bunch of memory and failing the tests
672+
without_tracing(|| {
673+
sim(|| {
674+
spawn_named($harness.run().primary(), "harness");
675+
676+
async {
677+
sleep(Duration::from_secs(120)).await;
678+
panic!("test timed out after {}", bach::time::Instant::now());
679+
}
680+
.spawn();
681+
});
671682
});
672683
}
673684
};
@@ -715,24 +726,26 @@ mod udp_sim {
715726
tests!(sim_test);
716727

717728
#[test]
718-
#[ignore = "TODO the CI currently doesn't like running these tests - need to figure out why"]
719729
fn fuzz_test() {
720-
bolero::check!()
721-
.with_generator((produce(), produce(), produce::<Vec<_>>().with().len(1..5)))
722-
.cloned()
723-
.with_test_time(Duration::from_secs(60))
724-
.for_each(|(client, server, requests)| {
725-
crate::testing::sim(|| {
726-
Harness {
727-
client,
728-
server,
729-
requests,
730-
..harness()
731-
}
732-
.run()
733-
.primary()
734-
.spawn();
735-
});
736-
});
730+
// The tracing logs end up consuming a bunch of memory and failing the tests
731+
without_tracing(|| {
732+
bolero::check!()
733+
.with_generator((produce(), produce(), produce::<Vec<_>>().with().len(1..5)))
734+
.cloned()
735+
.with_test_time(Duration::from_secs(60))
736+
.for_each(|(client, server, requests)| {
737+
crate::testing::sim(|| {
738+
Harness {
739+
client,
740+
server,
741+
requests,
742+
..harness()
743+
}
744+
.run()
745+
.primary()
746+
.spawn();
747+
});
748+
})
749+
});
737750
}
738751
}

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

Lines changed: 19 additions & 2 deletions
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 std::time::Duration;
4+
use std::{sync::OnceLock, time::Duration};
55

66
pub use bach::{ext, rand};
77

@@ -79,7 +79,10 @@ pub fn init_tracing() {
7979
.with_timer(Uptime::default())
8080
.compact(); // Use a less verbose output format.
8181

82-
let default_level = if cfg!(debug_assertions) {
82+
let default_level = if std::env::var("CI").is_ok() {
83+
// The CI runs out of memory if we log too much tracing data
84+
tracing::Level::INFO
85+
} else if cfg!(debug_assertions) {
8386
tracing::Level::DEBUG
8487
} else {
8588
tracing::Level::WARN
@@ -99,6 +102,20 @@ pub fn init_tracing() {
99102
});
100103
}
101104

105+
pub fn without_tracing<F: FnOnce() -> T, T>(f: F) -> T {
106+
// make sure the global subscriber is initialized before setting a local one
107+
init_tracing();
108+
109+
static FORCED: OnceLock<bool> = OnceLock::new();
110+
111+
// add the option to get logs with `S2N_LOG_FORCED=1`
112+
if *FORCED.get_or_init(|| std::env::var("S2N_LOG_FORCED").is_ok()) {
113+
return f();
114+
}
115+
116+
tracing::subscriber::with_default(tracing::subscriber::NoSubscriber::new(), f)
117+
}
118+
102119
#[derive(Default)]
103120
struct Uptime(tracing_subscriber::fmt::time::SystemTime);
104121

0 commit comments

Comments
 (0)