tcp-stress-test: Factor out thread count as constant.

This commit is contained in:
Moritz Ulrich 2016-07-30 09:01:13 +02:00
parent 2ad98a0b42
commit aaf8a6e108

View File

@ -21,6 +21,8 @@ use std::sync::mpsc::channel;
use std::time::Duration;
use std::thread::{self, Builder};
const TARGET_CNT: usize = 1000;
fn main() {
// This test has a chance to time out, try to not let it time out
thread::spawn(move|| -> () {
@ -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) {
@ -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);
}