Skip to content

Commit

Permalink
Rollup merge of rust-lang#35140 - the-kenny:tcp-stress-test-const-thr…
Browse files Browse the repository at this point in the history
…ead-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 rust-lang#35107
  • Loading branch information
sanxiyn committed Aug 1, 2016
2 parents 2effa89 + 3ea293d commit a790fbc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/test/run-pass/tcp-stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use std::sync::mpsc::channel;
use std::time::Duration;
use std::thread::{self, Builder};

const TARGET_CNT: usize = 200;

fn main() {
// This test has a chance to time out, try to not let it time out
thread::spawn(move|| -> () {
Expand All @@ -42,8 +44,9 @@ fn main() {
});

let (tx, rx) = channel();

let mut spawned_cnt = 0;
for _ in 0..1000 {
for _ in 0..TARGET_CNT {
let tx = tx.clone();
let res = Builder::new().stack_size(64 * 1024).spawn(move|| {
match TcpStream::connect(addr) {
Expand All @@ -66,6 +69,6 @@ fn main() {
for _ in 0..spawned_cnt {
rx.recv().unwrap();
}
assert_eq!(spawned_cnt, 1000);
assert_eq!(spawned_cnt, TARGET_CNT);
process::exit(0);
}

0 comments on commit a790fbc

Please sign in to comment.