diff --git a/crates/core/tests/control.rs b/crates/core/tests/control.rs index 8046c07..4ab81cd 100644 --- a/crates/core/tests/control.rs +++ b/crates/core/tests/control.rs @@ -274,15 +274,17 @@ async fn connector_slow_and_flood() { #[tokio::test(flavor = "multi_thread")] async fn connector_flood_15() { let (_c, _rx, p) = start().await; - // One loop, one after the other: the rate gate answers the first ~30 and then says busy. + // All at once: a sequential loop is slowed by the peer lookup and the 5 per second refill hides the limit. let codes: Vec = tokio::task::spawn_blocking(move || { - (0..40).map(|_| code(&send(p, format!("GET / HTTP/1.1\r\nHost: 127.0.0.1:{p}\r\nConnection: close\r\n\r\n").as_bytes()))).collect() + let req = format!("GET / HTTP/1.1\r\nHost: 127.0.0.1:{p}\r\nConnection: close\r\n\r\n"); + let jobs: Vec<_> = (0..40).map(|_| { let r = req.clone(); std::thread::spawn(move || code(&send(p, r.as_bytes()))) }).collect(); + jobs.into_iter().map(|j| j.join().unwrap()).collect() }) .await .unwrap(); let ok = codes.iter().filter(|c| **c == 200).count(); let busy = codes.iter().filter(|c| **c == 429).count(); - assert!(ok >= 25 && busy >= 5 && ok + busy == 40, "ok {ok} busy {busy} {codes:?}"); + assert!(ok >= 10 && busy >= 5 && ok + busy == 40, "ok {ok} busy {busy} {codes:?}"); } /// S037: connections over the limit of 16 at once get 429 "busy", not a silent close.