From 47ebc563860f1e5608dbdaf7603921c7676ed75f Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Sat, 14 May 2016 18:56:20 +0200 Subject: [PATCH] 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 --- src/test/run-pass/tcp-stress.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/test/run-pass/tcp-stress.rs b/src/test/run-pass/tcp-stress.rs index 52c920b6f5e03..48726f7cac9cd 100644 --- a/src/test/run-pass/tcp-stress.rs +++ b/src/test/run-pass/tcp-stress.rs @@ -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); }