This commit is contained in:
Alexey
2026-10-30 22:34:37 +03:00
parent e7e588ebe5
commit 5a5009174a
5 changed files with 242 additions and 66 deletions
+14 -5
View File
@@ -13,10 +13,10 @@ pub(super) fn me_connection_cleanup_capacity(max_connections: u32) -> usize {
#[cfg(test)]
mod tests {
use super::*;
use crate::transport::middle_proxy::{ConnRegistry, MeResponse};
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::Semaphore;
use crate::transport::middle_proxy::{ConnRegistry, MeResponse};
#[test]
fn me_cleanup_capacity_preserves_zero_and_finite_limits() {
@@ -25,7 +25,12 @@ mod tests {
(1, 129),
(128, 256),
(10_000, 10_128),
(u32::MAX, (u32::MAX as usize).saturating_add(128).min(Semaphore::MAX_PERMITS)),
(
u32::MAX,
(u32::MAX as usize)
.saturating_add(128)
.min(Semaphore::MAX_PERMITS),
),
] {
let capacity = me_connection_cleanup_capacity(configured);
assert_eq!(capacity, expected);
@@ -36,17 +41,21 @@ mod tests {
#[tokio::test]
async fn me_cleanup_capacity_zero_admits_512_simultaneous_leased_routes() {
let registry = Arc::new(ConnRegistry::with_route_and_cleanup_capacity(
8, me_connection_cleanup_capacity(0),
8,
me_connection_cleanup_capacity(0),
));
let mut clients = Vec::new();
for index in 0..512 {
let client = tokio::time::timeout(Duration::from_secs(1), registry.register_leased())
.await.unwrap_or_else(|_| panic!("registration {} blocked", index + 1))
.await
.unwrap_or_else(|_| panic!("registration {} blocked", index + 1))
.unwrap();
clients.push(client);
}
for (lease, mut receiver) in clients {
registry.route_nowait(lease.conn_id(), MeResponse::Ack(1)).await;
registry
.route_nowait(lease.conn_id(), MeResponse::Ack(1))
.await;
assert!(matches!(receiver.try_recv(), Ok(MeResponse::Ack(1))));
lease.unregister().await;
}