flybus: wait for the pending-connection events instead of timing them

pending_connections_are_bounded_and_hello_expires gave the router 20 ms
to register a connection and then slept 80 ms past a 40 ms hello timeout
before reading the count once. Both are claims about how fast this box
is, not about the router: the first failed once in 20 whole-crate runs
beside four busy loops. Both now wait for the event they are about, under
the suite's ordinary ten-second bound, so the test still fails if a
pending connection never registers or a pending Hello never expires.
This commit is contained in:
dev 2026-09-22 17:12:46 +00:00
parent 2af1189ac3
commit 9bed780cb9

View file

@ -266,13 +266,14 @@ async fn pending_connections_are_bounded_and_hello_expires() {
let router = Router::new(config).unwrap(); let router = Router::new(config).unwrap();
let pending = router.connect_in_memory_as("first"); let pending = router.connect_in_memory_as("first");
tokio::time::timeout(Duration::from_millis(20), async { // Registration happens on the router's own task. How long that takes is this box's
// business; that it happens is the router's.
within("the pending connection occupies the only slot", async {
while router.stats().connections != 1 { while router.stats().connections != 1 {
tokio::task::yield_now().await; tokio::time::sleep(Duration::from_millis(1)).await;
} }
}) })
.await .await;
.unwrap();
assert_eq!(router.stats().connections, 1); assert_eq!(router.stats().connections, 1);
let refused = Client::connect( let refused = Client::connect(
router.connect_in_memory_as("second"), router.connect_in_memory_as("second"),
@ -280,7 +281,14 @@ async fn pending_connections_are_bounded_and_hello_expires() {
) )
.await; .await;
assert_eq!(refused.unwrap_err().code, ErrorCode::RouterLost); assert_eq!(refused.unwrap_err().code, ErrorCode::RouterLost);
tokio::time::sleep(Duration::from_millis(80)).await; // The 40 ms hello timeout expires on the router's clock: wait for the expiry to be
// observed rather than sleep past it and read the count once.
within("the pending Hello expires", async {
while router.stats().connections != 0 {
tokio::time::sleep(Duration::from_millis(1)).await;
}
})
.await;
assert_eq!(router.stats().connections, 0, "pending Hello timed out"); assert_eq!(router.stats().connections, 0, "pending Hello timed out");
drop(pending); drop(pending);