Skip to content

Commit

Permalink
test: assert that all tcp-stress threads get spawned
Browse files Browse the repository at this point in the history
System limits may restrict the number of threads effectively spawned
by this test (eg. systemd recently introduced a 512 tasks per unit
maximum default).
This commit explicitly asserts on the expected number of threads,
making failures due to system limits easier to spot.
More details at https://bugs.debian.org/822325

Signed-off-by: Luca Bruno <lucab@debian.org>
  • Loading branch information
lucab committed May 14, 2016
1 parent 6ba8a1a commit 47ebc56
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/test/run-pass/tcp-stress.rs
Expand Up @@ -41,9 +41,10 @@ fn main() {
});

let (tx, rx) = channel();
let mut spawned_cnt = 0;
for _ in 0..1000 {
let tx = tx.clone();
Builder::new().stack_size(64 * 1024).spawn(move|| {
let res = Builder::new().stack_size(64 * 1024).spawn(move|| {
match TcpStream::connect(addr) {
Ok(mut stream) => {
stream.write(&[1]);
Expand All @@ -53,13 +54,17 @@ fn main() {
}
tx.send(()).unwrap();
});
if let Ok(_) = res {
spawned_cnt += 1;
};
}

// Wait for all clients to exit, but don't wait for the server to exit. The
// server just runs infinitely.
drop(tx);
for _ in 0..1000 {
for _ in 0..spawned_cnt {
rx.recv().unwrap();
}
assert_eq!(spawned_cnt, 1000);
process::exit(0);
}

0 comments on commit 47ebc56

Please sign in to comment.