use std::time::Duration;
pub const QUEUE_WAIT: Duration = Duration::from_secs(2);
pub fn qos_priority(qos: &str) -> u8 {
match qos {
"realtime" => 0,
"interactive" => 1,
"batch" => 2,
_ => 3,
}
}
pub fn is_queue_eligible(qos: &str) -> bool {
matches!(qos, "realtime" | "interactive")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ordering_realtime_highest() {
assert!(qos_priority("realtime") < qos_priority("interactive"));
assert!(qos_priority("interactive") < qos_priority("batch"));
assert!(qos_priority("batch") <= qos_priority("best_effort"));
}
#[test]
fn unknown_and_best_effort_lowest() {
assert_eq!(qos_priority("best_effort"), 3);
assert_eq!(qos_priority("best-effort"), 3);
assert_eq!(qos_priority("nonsense"), 3);
}
#[test]
fn only_realtime_interactive_eligible() {
assert!(is_queue_eligible("realtime"));
assert!(is_queue_eligible("interactive"));
for q in ["batch", "best_effort", "best-effort", "unknown"] {
assert!(!is_queue_eligible(q), "{q} must not be queue-eligible");
}
}
}