Some checks failed
rust-ci / checks (push) Has been cancelled
- 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)
140 lines
4.7 KiB
Rust
140 lines
4.7 KiB
Rust
use icenet_core::{LinkKind, NodeId, TrafficClass};
|
|
use icenet_sim::{City, DeliveryState, DeviceRole, metrics};
|
|
|
|
#[test]
|
|
fn bulk_is_queued_when_only_slow_links_remain() {
|
|
let mut city = City::demo();
|
|
assert!(city.set_link_enabled(2, false));
|
|
let id = city.send(NodeId(1), NodeId(3), TrafficClass::Bulk, 5_000_000);
|
|
assert_eq!(
|
|
city.messages.iter().find(|m| m.id == id).unwrap().status,
|
|
DeliveryState::Queued
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn message_delivers_after_virtual_time_advance() {
|
|
let mut city = City::demo();
|
|
city.send(NodeId(1), NodeId(3), TrafficClass::Bulk, 50_000);
|
|
city.tick(200_000);
|
|
assert_eq!(city.messages[0].status, DeliveryState::Delivered);
|
|
}
|
|
|
|
#[test]
|
|
fn queued_message_recovers_when_fast_link_returns() {
|
|
let mut city = City::demo();
|
|
city.set_link_enabled(2, false);
|
|
city.send(NodeId(1), NodeId(3), TrafficClass::Bulk, 100);
|
|
assert_eq!(city.messages[0].status, DeliveryState::Queued);
|
|
city.set_link_enabled(2, true);
|
|
city.tick(1);
|
|
assert_eq!(city.messages[0].status, DeliveryState::InFlight);
|
|
}
|
|
|
|
#[test]
|
|
fn slower_link_kind_reschedules_an_in_flight_message() {
|
|
let mut city = City::demo();
|
|
let id = city.send(NodeId(1), NodeId(3), TrafficClass::Bulk, 5_000_000);
|
|
let before = city.messages[0].due_ms.expect("scheduled");
|
|
assert!(city.set_link_kind(3, LinkKind::Internet));
|
|
city.tick(1);
|
|
let after = city.messages[0].due_ms.expect("still scheduled");
|
|
assert!(after > before, "due {after} must move past {before}");
|
|
assert_eq!(city.messages[0].id, id);
|
|
}
|
|
|
|
#[test]
|
|
fn first_route_timestamp_is_not_restamped_after_requeue() {
|
|
let mut city = City::demo();
|
|
assert!(city.set_link_enabled(2, false));
|
|
city.send(NodeId(1), NodeId(3), TrafficClass::Bulk, 100);
|
|
city.tick(1_000);
|
|
assert!(city.set_link_enabled(2, true));
|
|
city.tick(1);
|
|
let first = city.messages[0].first_route_ms;
|
|
assert_eq!(first, Some(1_001));
|
|
assert!(city.set_link_enabled(2, false));
|
|
city.tick(1);
|
|
assert_eq!(city.messages[0].status, DeliveryState::Queued);
|
|
assert!(city.set_link_enabled(2, true));
|
|
city.tick(1);
|
|
assert_eq!(city.messages[0].first_route_ms, first);
|
|
}
|
|
|
|
#[test]
|
|
fn empty_city_has_no_devices_links_or_messages() {
|
|
let city = City::empty();
|
|
assert!(city.devices.is_empty());
|
|
assert!(city.links.is_empty());
|
|
assert!(city.messages.is_empty());
|
|
assert_eq!(city.now_ms, 0);
|
|
}
|
|
|
|
#[test]
|
|
fn identical_action_scripts_produce_byte_identical_exports() {
|
|
let first = run_script();
|
|
let second = run_script();
|
|
assert_eq!(
|
|
metrics::messages_csv(&first),
|
|
metrics::messages_csv(&second)
|
|
);
|
|
assert_eq!(
|
|
metrics::scenario_json(&first),
|
|
metrics::scenario_json(&second)
|
|
);
|
|
assert_eq!(metrics::summarize(&first), metrics::summarize(&second));
|
|
}
|
|
|
|
fn run_script() -> City {
|
|
let mut city = City::demo();
|
|
assert!(city.set_link_enabled(2, false));
|
|
city.send(NodeId(1), NodeId(3), TrafficClass::Bulk, 5_000_000);
|
|
city.send(NodeId(1), NodeId(3), TrafficClass::Text, 128);
|
|
city.tick(1_000);
|
|
assert!(city.set_link_enabled(2, true));
|
|
city.tick(120_000);
|
|
let extra = city.add_device("Extra".to_owned(), DeviceRole::Client);
|
|
assert!(city.add_link(extra, NodeId(5), LinkKind::Internet));
|
|
city.send_with_ttl(extra, NodeId(6), TrafficClass::Bulk, 1_000, 1);
|
|
city.tick(10);
|
|
city
|
|
}
|
|
|
|
#[test]
|
|
fn cutting_the_route_before_a_coarse_tick_never_yields_delivered() {
|
|
let mut city = City::demo();
|
|
let id = city.send(NodeId(1), NodeId(3), TrafficClass::Bulk, 5_000_000);
|
|
for index in 0..city.links.len() {
|
|
assert!(city.set_link_enabled(index, false));
|
|
}
|
|
// One huge step jumps far past `due_ms`; the cut still happened first.
|
|
city.tick(1_000_000);
|
|
let status = city.messages.iter().find(|m| m.id == id).unwrap().status;
|
|
assert_eq!(status, DeliveryState::Queued);
|
|
}
|
|
|
|
#[test]
|
|
fn taking_a_relay_offline_before_arrival_does_not_deliver() {
|
|
let mut city = City::demo();
|
|
city.send(NodeId(1), NodeId(3), TrafficClass::Bulk, 5_000_000);
|
|
assert!(city.set_device_online(NodeId(5), false));
|
|
city.tick(1_000_000);
|
|
assert_ne!(city.messages[0].status, DeliveryState::Delivered);
|
|
}
|
|
|
|
#[test]
|
|
fn a_still_valid_route_is_delivered_normally_after_a_coarse_tick() {
|
|
let mut city = City::demo();
|
|
city.send(NodeId(1), NodeId(3), TrafficClass::Bulk, 5_000_000);
|
|
city.tick(1_000_000);
|
|
assert_eq!(city.messages[0].status, DeliveryState::Delivered);
|
|
}
|
|
|
|
#[test]
|
|
fn a_cut_that_is_repaired_before_the_tick_reroutes_without_false_delivery() {
|
|
let mut city = City::demo();
|
|
city.send(NodeId(1), NodeId(3), TrafficClass::Bulk, 5_000_000);
|
|
assert!(city.set_link_enabled(3, false));
|
|
city.tick(1);
|
|
assert_ne!(city.messages[0].status, DeliveryState::Delivered);
|
|
}
|