This commit is contained in:
Mateusz Gruszczyński committed 2026-10-05 10:58:50 +02:00
1 parent c819f0a335
commit e1a59f6e56
53 files changed
+817 -380

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
mod tests {
use super::*;
fn backend(id: &str, port: u16) -> Backend {
serde_json::from_value(serde_json::json!({
"id": id,
"url": format!("http://127.0.0.1:{port}"),
"protocol": "http1",
"allow_private": true
}))
.unwrap()
}
#[test]
fn generation_recycles_after_request_budget() {
let backend = backend("rotation-test", 18081);
let mut keepalive = crate::balance::Keepalive::default();
keepalive.pool_recycle_requests = 2;
keepalive.pool_recycle_seconds = 0;
let client = client_with_keepalive(
&backend,
AddressPolicy::new(&backend).unwrap(),
false,
&keepalive,
)
.unwrap();
client.inner.client_for_request();
client.inner.client_for_request();
assert_eq!(client.rotation_stats().rotations, 0);
client.inner.client_for_request();
let stats = client.rotation_stats();
assert_eq!(stats.rotations, 1);
assert_eq!(stats.generation, 1);
}
#[test]
fn generation_recycling_can_be_disabled() {
let backend = backend("rotation-off", 18082);
let mut keepalive = crate::balance::Keepalive::default();
keepalive.pool_recycle_requests = 0;
keepalive.pool_recycle_seconds = 0;
let client = client_with_keepalive(
&backend,
AddressPolicy::new(&backend).unwrap(),
false,
&keepalive,
)
.unwrap();
for _ in 0..10 {
client.inner.client_for_request();
}
assert_eq!(client.rotation_stats().rotations, 0);
}
}