Skip to content

Commit a790fbc

Browse files
authored
Rollup merge of #35140 - the-kenny:tcp-stress-test-const-thread-count, r=alexcrichton
tcp-stress-test: Pull out thread count as a constant This PR factors out the number of concurrent threads used in `tcp-stress-test.rs` to a constant at the top of the file. We at @NixOS had to lower our thread count as the chrooted-builds don't allow that many threads. This change will make it easier to lower/increase the count in the future (I actually forgot to change the second `1000` when I was working on this). Another benefit is the removal of magic numbers in the test suite. This is related to #35107
2 parents 2effa89 + 3ea293d commit a790fbc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/test/run-pass/tcp-stress.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use std::sync::mpsc::channel;
2121
use std::time::Duration;
2222
use std::thread::{self, Builder};
2323

24+
const TARGET_CNT: usize = 200;
25+
2426
fn main() {
2527
// This test has a chance to time out, try to not let it time out
2628
thread::spawn(move|| -> () {
@@ -42,8 +44,9 @@ fn main() {
4244
});
4345

4446
let (tx, rx) = channel();
47+
4548
let mut spawned_cnt = 0;
46-
for _ in 0..1000 {
49+
for _ in 0..TARGET_CNT {
4750
let tx = tx.clone();
4851
let res = Builder::new().stack_size(64 * 1024).spawn(move|| {
4952
match TcpStream::connect(addr) {
@@ -66,6 +69,6 @@ fn main() {
6669
for _ in 0..spawned_cnt {
6770
rx.recv().unwrap();
6871
}
69-
assert_eq!(spawned_cnt, 1000);
72+
assert_eq!(spawned_cnt, TARGET_CNT);
7073
process::exit(0);
7174
}

0 commit comments

Comments
 (0)