use super::*;
use crate::messages::{CONNECTIVITY_LOST_CODE, FARM_OK_CODES};
#[test]
fn test_is_benign_connectivity_notice() {
for code in FARM_OK_CODES {
let notice = Notice::synthesized(code, "farm OK".into());
assert!(is_benign_connectivity_notice(¬ice), "code {code} should be benign");
}
let notice = Notice::synthesized(CONNECTIVITY_RESTORED_DATA_MAINTAINED_CODE, "restored, data maintained".into());
assert!(is_benign_connectivity_notice(¬ice), "code 1102 should be benign");
for code in [
2100,
2103, 2105, 2157, 2107,
2108, 2119, 2169,
200, CONNECTIVITY_LOST_CODE, CONNECTIVITY_RESTORED_DATA_LOST_CODE, ] {
let notice = Notice::synthesized(code, "not benign".into());
assert!(!is_benign_connectivity_notice(¬ice), "code {code} should not be benign");
}
}
#[test]
fn test_log_unrouted_notice_traverses_all_severities() {
log_unrouted_notice(&Notice::synthesized(FARM_OK_CODES[0], "farm OK".into()));
log_unrouted_notice(&Notice::synthesized(CONNECTIVITY_RESTORED_DATA_MAINTAINED_CODE, "1102 info".into()));
log_unrouted_notice(&Notice::synthesized(2103, "farm broken".into()));
log_unrouted_notice(&Notice::synthesized(CONNECTIVITY_RESTORED_DATA_LOST_CODE, "1101 warn".into()));
log_unrouted_notice(&Notice::synthesized(CONNECTIVITY_LOST_CODE, "1100 error".into()));
log_unrouted_notice(&Notice::synthesized(200, "no security definition".into()));
}
#[test]
fn test_fibonacci_backoff() {
let mut backoff = FibonacciBackoff::new(10);
assert_eq!(backoff.next_delay(), Duration::from_secs(1));
assert_eq!(backoff.next_delay(), Duration::from_secs(2));
assert_eq!(backoff.next_delay(), Duration::from_secs(3));
assert_eq!(backoff.next_delay(), Duration::from_secs(5));
assert_eq!(backoff.next_delay(), Duration::from_secs(8));
assert_eq!(backoff.next_delay(), Duration::from_secs(10)); assert_eq!(backoff.next_delay(), Duration::from_secs(10)); }