v0.34.0_7
This commit is contained in:
1 parent
47ce1f18c2
commit
b6a3e12225
21 files changed
+471
-84
No files matched your search
@@ -75,4 +75,68 @@ mod tests {
|
||||
assert_eq!(user_agent_family("curl/8.12.1"), "curl");
|
||||
assert_eq!(user_agent_family("ExampleBot/1.0"), "bot");
|
||||
}
|
||||
#[test]
|
||||
fn status_top_list_preserves_common_and_extension_family_names() {
|
||||
let mut counters = Counters::default();
|
||||
for status in [100, 200, 302, 404, 503, 701] {
|
||||
counters.record(Sample {
|
||||
vhost: "test".into(), route: None, method: "GET".into(),
|
||||
path: "/".into(), client_ip: None, status,
|
||||
duration_ms: 1, request_bytes: 0, response_bytes: 1,
|
||||
cache: "BYPASS", source: "reverse_proxy",
|
||||
user_agent: None, country: None,
|
||||
});
|
||||
}
|
||||
let labels: std::collections::HashSet<_> = counters.view().statuses.into_iter()
|
||||
.map(|entry| entry.value).collect();
|
||||
for label in ["1xx", "2xx", "3xx", "4xx", "5xx", "7xx"] {
|
||||
assert!(labels.contains(label));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn user_agent_matching_is_ascii_case_insensitive_even_with_unicode() {
|
||||
for (agent, expected) in [
|
||||
("MOZILLA/5.0 ChRoMe/120.0", "chrome"),
|
||||
("żółw / uSER-BOT", "bot"),
|
||||
("CURL/8.0", "curl"),
|
||||
("wGeT/1.24", "wget"),
|
||||
("Ąęć PYTHON-Requests", "python"),
|
||||
("Mozilla/5.0 EdG/110", "edge"),
|
||||
("Random ∂x/42", "other"),
|
||||
] {
|
||||
assert_eq!(user_agent_family(agent), expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn batched_worker_keeps_exact_counts_and_bounded_vhosts() {
|
||||
let shutdown = CancellationToken::new();
|
||||
let analytics = Analytics::start(shutdown.clone());
|
||||
for id in 0..130 {
|
||||
analytics.push(Sample {
|
||||
vhost: if id % 2 == 0 { "left".into() } else { "right".into() },
|
||||
route: None, method: "GET".into(), path: "/small".into(),
|
||||
client_ip: None, status: 200, duration_ms: 1,
|
||||
request_bytes: 0, response_bytes: 1040,
|
||||
cache: "BYPASS", source: "reverse_proxy",
|
||||
user_agent: None, country: None,
|
||||
});
|
||||
}
|
||||
tokio::time::timeout(std::time::Duration::from_secs(2), async {
|
||||
while analytics.view(Some("left")).data.requests != 65
|
||||
|| analytics.view(Some("right")).data.requests != 65
|
||||
{
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
}).await.expect("analytics should drain two batches");
|
||||
let all = analytics.view(None).data;
|
||||
assert_eq!(all.requests, 130);
|
||||
assert_eq!(all.response_bytes, 130 * 1040);
|
||||
assert_eq!(analytics.dropped.load(Ordering::Relaxed), 0);
|
||||
assert_eq!(analytics.reset(Some("left")), 1);
|
||||
assert_eq!(analytics.view(None).data.requests, 65);
|
||||
shutdown.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user