Skip to content

Commit 47ebc56

Browse files
committed
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 <[email protected]>
1 parent 6ba8a1a commit 47ebc56

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/test/run-pass/tcp-stress.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ fn main() {
4141
});
4242

4343
let (tx, rx) = channel();
44+
let mut spawned_cnt = 0;
4445
for _ in 0..1000 {
4546
let tx = tx.clone();
46-
Builder::new().stack_size(64 * 1024).spawn(move|| {
47+
let res = Builder::new().stack_size(64 * 1024).spawn(move|| {
4748
match TcpStream::connect(addr) {
4849
Ok(mut stream) => {
4950
stream.write(&[1]);
@@ -53,13 +54,17 @@ fn main() {
5354
}
5455
tx.send(()).unwrap();
5556
});
57+
if let Ok(_) = res {
58+
spawned_cnt += 1;
59+
};
5660
}
5761

5862
// Wait for all clients to exit, but don't wait for the server to exit. The
5963
// server just runs infinitely.
6064
drop(tx);
61-
for _ in 0..1000 {
65+
for _ in 0..spawned_cnt {
6266
rx.recv().unwrap();
6367
}
68+
assert_eq!(spawned_cnt, 1000);
6469
process::exit(0);
6570
}

0 commit comments

Comments
 (0)