use icenet_core::{NodeId, ServiceId}; use icenet_guard::{Context, Guard, Limits, Verdict}; fn context(queue_depth: usize, sequence: u64) -> Context { Context { authenticated: true, peer: NodeId(1), service: ServiceId(7), payload_bytes: 1, sequence, now_ms: 0, queue_depth, } } #[test] fn full_queue_is_denied_before_accepting_more_work() { let limits = Limits { max_queue_depth: 2, rate_per_second: 0, ..Limits::default() }; let mut guard = Guard::new([ServiceId(7)], limits); assert_eq!(guard.check(context(1, 1)), Verdict::Permit); assert_eq!(guard.check(context(2, 2)), Verdict::Deny("queue_full")); } #[test] fn empty_queue_below_the_cap_is_permitted() { let limits = Limits { max_queue_depth: 2, rate_per_second: 0, ..Limits::default() }; let mut guard = Guard::new([ServiceId(7)], limits); assert_eq!(guard.check(context(0, 1)), Verdict::Permit); }