ICE-NET/workspace/crates/icenet-guard/tests/queue.rs
loki5512344 2e61688eb3
Some checks failed
rust-ci / checks (push) Has been cancelled
Initial import: ICE-NET research docs and Rust workspace (v0.4)
- Rust workspace: 7 library crates, icenetd CLI, icenet-city (Slint GUI)
- Sim: fix false Delivered after a route cut, derive traffic class from
  payload size, per-link airtime slots (link capacity, queueing)
- Docs: single docs/STATUS.md for all figures, remove v0.2/egui leftovers,
  drop unimplemented seed claims, uncheck store-and-forward
- License: LGPL-3.0-or-later (LICENSE, LICENSES/GPL-3.0.txt)
2026-11-13 12:28:48 +01:00

37 lines
1,006 B
Rust

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);
}