use dhat::{HeapStats, Profiler};
use osproxy_spi::HttpMethod;
use osproxy_transport::classify;
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
fn allocs(f: impl FnOnce()) -> u64 {
let before = HeapStats::get().total_blocks;
f();
HeapStats::get().total_blocks - before
}
#[test]
fn classify_allocation_budgets() {
if std::env::var_os("LLVM_PROFILE_FILE").is_some() {
return;
}
let _profiler = Profiler::builder().testing().build();
let n = allocs(|| {
let _ = std::hint::black_box(classify(HttpMethod::Put, "/orders/_doc/acme:1"));
});
assert_eq!(n, CLASSIFY_INGEST_ALLOCS, "classify ingest-by-id budget");
let n = allocs(|| {
let _ = std::hint::black_box(classify(HttpMethod::Post, "/orders/_search"));
});
assert_eq!(n, CLASSIFY_SEARCH_ALLOCS, "classify search budget");
}
const CLASSIFY_INGEST_ALLOCS: u64 = 2;
const CLASSIFY_SEARCH_ALLOCS: u64 = 1;