added unittest for all subscription
This commit is contained in:
parent
819c121fd7
commit
b7da30d741
@ -18,7 +18,12 @@
|
|||||||
//! manager.
|
//! manager.
|
||||||
//! 4. Each event receiver and/or subscriber gets a receiver component. The sender component is
|
//! 4. Each event receiver and/or subscriber gets a receiver component. The sender component is
|
||||||
//! used with the [SendEventProvider] trait and the subscription API provided by the
|
//! used with the [SendEventProvider] trait and the subscription API provided by the
|
||||||
//! [EventManager] to subscribe for individual events or whole group of events.
|
//! [EventManager] to subscribe for individual events, whole group of events or all events
|
||||||
|
//!
|
||||||
|
//! Some components like a PUS Event Service or PUS Event Action Service might require all
|
||||||
|
//! events to package them as telemetry or start actions where applicable.
|
||||||
|
//! Other components might only be interested in certain events. For example, a thermal system
|
||||||
|
//! handler might only be interested in temperature events generated by a thermal sensor component.
|
||||||
use crate::events::{GenericEvent, LargestEventRaw, LargestGroupIdRaw};
|
use crate::events::{GenericEvent, LargestEventRaw, LargestGroupIdRaw};
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use alloc::vec;
|
use alloc::vec;
|
||||||
@ -402,4 +407,36 @@ mod tests {
|
|||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
check_handled_event(res.unwrap(), event_1, 1);
|
check_handled_event(res.unwrap(), event_1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_all_events_listener() {
|
||||||
|
let (event_sender, manager_queue) = channel();
|
||||||
|
let event_man_receiver = MpscEventReceiver {
|
||||||
|
mpsc_receiver: manager_queue,
|
||||||
|
};
|
||||||
|
let mut event_man: EventManager<SendError<EventAndParams>, EventU32> =
|
||||||
|
EventManager::new(Box::new(event_man_receiver), 128);
|
||||||
|
let event_0 = EventU32::new(Severity::INFO, 0, 5).unwrap();
|
||||||
|
let event_1 = EventU32::new(Severity::HIGH, 1, 0).unwrap();
|
||||||
|
let (event_0_tx_0, all_events_rx) = channel();
|
||||||
|
let all_events_listener = MpscEventSenderQueue {
|
||||||
|
id: 0,
|
||||||
|
mpsc_sender: event_0_tx_0,
|
||||||
|
};
|
||||||
|
event_man.subscribe_all(all_events_listener);
|
||||||
|
event_sender
|
||||||
|
.send((event_0, None))
|
||||||
|
.expect("Triggering event 0 failed");
|
||||||
|
event_sender
|
||||||
|
.send((event_1, None))
|
||||||
|
.expect("Triggering event 1 failed");
|
||||||
|
let res = event_man.try_event_handling();
|
||||||
|
assert!(res.is_ok());
|
||||||
|
check_handled_event(res.unwrap(), event_0, 1);
|
||||||
|
let res = event_man.try_event_handling();
|
||||||
|
assert!(res.is_ok());
|
||||||
|
check_handled_event(res.unwrap(), event_1, 1);
|
||||||
|
check_next_event(event_0, &all_events_rx);
|
||||||
|
check_next_event(event_1, &all_events_rx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user