test: consolidate formatter and hub policy cases
This commit is contained in:
1 parent
00fd0ebb15
commit
39d414d588
2 files changed
+56
-92
No files matched your search
+15
-37
@@ -1175,45 +1175,23 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn machine_echo_reply_metadata_unavailable_prints_none() {
|
fn machine_echo_reply_metadata_prints_observed_and_unavailable_values() {
|
||||||
let line = format_event(&reply_event(), OutputMode::Machine).unwrap();
|
let cases = [
|
||||||
|
(PacketMeta::default(), ("none", "none", "none", "none")),
|
||||||
|
(packet_meta(0, 0, 0), ("0", "0", "0", "none")),
|
||||||
|
(packet_meta(186, 46, 2), ("186", "46", "2", "none")),
|
||||||
|
(
|
||||||
|
packet_meta_with_timestamp(Some(UNIX_EPOCH + Duration::new(1, 234))),
|
||||||
|
("none", "none", "none", "1000000234"),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
assert_machine_packet_meta(&line, "none", "none", "none", "none");
|
for (packet_meta, (traffic_class, dscp, ecn, kernel_rx_ns)) in cases {
|
||||||
}
|
let line =
|
||||||
|
format_event(&reply_event_with_meta(packet_meta), OutputMode::Machine).unwrap();
|
||||||
|
|
||||||
#[test]
|
assert_machine_packet_meta(&line, traffic_class, dscp, ecn, kernel_rx_ns);
|
||||||
fn machine_echo_reply_metadata_observed_zero_prints_zero() {
|
}
|
||||||
let line = format_event(
|
|
||||||
&reply_event_with_meta(packet_meta(0, 0, 0)),
|
|
||||||
OutputMode::Machine,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_machine_packet_meta(&line, "0", "0", "0", "none");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn machine_echo_reply_metadata_dscp_46_ecn_2_prints_values() {
|
|
||||||
let line = format_event(
|
|
||||||
&reply_event_with_meta(packet_meta(186, 46, 2)),
|
|
||||||
OutputMode::Machine,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_machine_packet_meta(&line, "186", "46", "2", "none");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn machine_echo_reply_metadata_kernel_rx_timestamp_prints_ns() {
|
|
||||||
let line = format_event(
|
|
||||||
&reply_event_with_meta(packet_meta_with_timestamp(Some(
|
|
||||||
UNIX_EPOCH + Duration::new(1, 234),
|
|
||||||
))),
|
|
||||||
OutputMode::Machine,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_machine_packet_meta(&line, "none", "none", "none", "1000000234");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -290,14 +290,16 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
fn assert_next(
|
||||||
fn publishes_to_one_subscriber() {
|
sub: &EventSubscription,
|
||||||
let hub = EventHub::new();
|
expected: Result<Option<&str>, EventSubscriptionError>,
|
||||||
let sub = hub.subscribe(SubscriberConfig::default()).unwrap();
|
) {
|
||||||
|
match (sub.try_recv(), expected) {
|
||||||
hub.publish(event(1));
|
(Ok(Some(event)), Ok(Some(message))) => assert_eq!(event_message(event), message),
|
||||||
|
(Ok(None), Ok(None)) => {}
|
||||||
assert_eq!(event_message(sub.try_recv().unwrap().unwrap()), "event-1");
|
(Err(actual), Err(expected)) => assert_eq!(actual, expected),
|
||||||
|
(actual, expected) => panic!("expected {expected:?}, got {actual:?}"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -313,56 +315,40 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn drop_newest_keeps_existing_events() {
|
fn full_subscriber_overflow_policy_is_applied() {
|
||||||
let hub = EventHub::new();
|
let cases = [
|
||||||
let sub = hub
|
(
|
||||||
.subscribe(SubscriberConfig {
|
SubscriberOverflow::DropNewest,
|
||||||
capacity: 1,
|
Ok(Some("event-1")),
|
||||||
overflow: SubscriberOverflow::DropNewest,
|
Ok(None),
|
||||||
})
|
),
|
||||||
.unwrap();
|
(
|
||||||
|
SubscriberOverflow::DropOldest,
|
||||||
|
Ok(Some("event-2")),
|
||||||
|
Ok(None),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
SubscriberOverflow::Disconnect,
|
||||||
|
Err(EventSubscriptionError::Disconnected),
|
||||||
|
Err(EventSubscriptionError::Disconnected),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
hub.publish(event(1));
|
for (overflow, first_expected, second_expected) in cases {
|
||||||
hub.publish(event(2));
|
let hub = EventHub::new();
|
||||||
|
let sub = hub
|
||||||
|
.subscribe(SubscriberConfig {
|
||||||
|
capacity: 1,
|
||||||
|
overflow,
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(event_message(sub.try_recv().unwrap().unwrap()), "event-1");
|
hub.publish(event(1));
|
||||||
assert!(sub.try_recv().unwrap().is_none());
|
hub.publish(event(2));
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
assert_next(&sub, first_expected);
|
||||||
fn drop_oldest_replaces_existing_events() {
|
assert_next(&sub, second_expected);
|
||||||
let hub = EventHub::new();
|
}
|
||||||
let sub = hub
|
|
||||||
.subscribe(SubscriberConfig {
|
|
||||||
capacity: 1,
|
|
||||||
overflow: SubscriberOverflow::DropOldest,
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
hub.publish(event(1));
|
|
||||||
hub.publish(event(2));
|
|
||||||
|
|
||||||
assert_eq!(event_message(sub.try_recv().unwrap().unwrap()), "event-2");
|
|
||||||
assert!(sub.try_recv().unwrap().is_none());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn disconnect_removes_full_subscriber() {
|
|
||||||
let hub = EventHub::new();
|
|
||||||
let sub = hub
|
|
||||||
.subscribe(SubscriberConfig {
|
|
||||||
capacity: 1,
|
|
||||||
overflow: SubscriberOverflow::Disconnect,
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
hub.publish(event(1));
|
|
||||||
hub.publish(event(2));
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
sub.try_recv().unwrap_err(),
|
|
||||||
EventSubscriptionError::Disconnected
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in new issue
Block a user