test: assert that all tcp-stress threads get spawned

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>
This commit is contained in:
Luca Bruno 2016-05-14 18:56:20 +02:00
parent 6ba8a1a657
commit 47ebc56386
No known key found for this signature in database
GPG Key ID: A9834A2252078E4E

View File

@ -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]);
@ -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);
}